Category: Programming

Random C# Notes. Using Visual Studio 2010. Some of this information has obtained through self-discovery, books, or random Google searches from other sites. I will give credit to the original author where due.

These are just plain code notes- not meant to be a tutorial.

Code is in italics.

Round up/down a number or variable:

Math.Round(number, x);

Rounds a number “number” by “x” amount of places.

Math.Round(37.777, 2); //will result in 37.78

Create and activate a “Reset” or “Clear” button. This is useful if you want to clear the user’s entry. This code needs to be added after double-clicking the button which will “clear” or “reset” the field.

TextBox.Clear(); //(WPF)TextBox.ResetText(); //(Windows Form Application)
label2.Text = ” “; // This sets the code for the label as one blank space, making it look empty (it’s not really empty, its value is a blank space… but it works, WPF)

I’ve written a neat little program using Python 2.6.4, which allows me to list the folders in a directory that match a specific criteria that I’ve set.

Here is a bit of history and reason for the program, before I describe it.

When I began ripping my CD collection with EAC and iTunesEncode, I was still fairly new to EAC, and had very, very little previous exposure and experience with the program. To make a long story short, I ripped some CDs, which – without taking notice right away – need to be re-ripped due to incorrect settings in EAC and iTunesEncode, since I was still playing with the different settings and parameters.

When I went back to add these to iTunes for properly tagging, adding an album art and organizing them in my Lossless Library, I discovered that I had quite a few of these “ripped” CDs that didn’t play, so I labeled the folder name “Artist Name – Album Name + ‘Needs RE-RIP’, with the idea of later going back to these CDs and ripping them again.

But instead of going through the folder and manually picking out which ones I had earlier tagged to be re-ripped, I wrote some Python code to help me do this.
The program is quite simple: Lists the folders in the EAC – Ripped directory that have the word “RIP” anywhere in the directory name; a process that I would have had to do manually. Instead, the small program picks out those which need ripping again, puts them on a list, and saves this list to a file! Now it’s much easier to pick out the ones that I need, instead of manually going through the directory.

Now – I haven’t got much programming experience – just some Python, C, C++ stuff that I’ve learned in school and studied/practiced on my own. I used the Internet as a refresher to help me remember how to open a file, and write to it, and how to list the contents of a directory. Besides that, the rest I coded by using previous examples and experience.

Anyways, without much further blabber, here is the code and the output. Feel free to leave some comments, use it and change it a bit if need.

*******************************************************************************************************************************
Again – this is quite a basic program, but it does two things for me: Saves me some time, and, more importantly – gives me some more needed coding experience!

Additional Note: The spacing and indentation is not set correctly – not sure why it was not displayed correctly. Also, this was created on a Mac, so the directory paths are different if the program were to run in a PC.