I'm starting to get the hang of writing VB.NET code--very simple jobs, but covering some esoteric subject matter. The first two tasks I needed to accomplish came about because I decide to import my (rather large) CD collection onto my new (also rather large) external hard drive; I used Apple’s iTunes. iTunes uses an online database to identify each CD and employs the information to create folder (i.e. album) and track (song) names. These names are truncated and/or abbreviated to fit file systems which only accommodate short file/directory names. Sometimes, the database cannot identify the album; as I have the original in hand, I can supply the missing information; unfortunately, iTunes makes no provision for this! I entered the missing info into a plain text file.

My first program asked for a target folder then inspected it for a text file called titles.txt. If found, it opened the text file and counted the number of .m4a (music) files in the folder. If the text file had the same number of titles as tracks in the folder, it renamed the tracks to match the names. Unfortunately, there are a few illegal characters where file/folder names are concerned. The program has provisions for replacing invalid characters as designated by the user. This worked great for the song titles which were missing!

RenameSongs3.zip


My second task was a bit more daunting! The actual .m4a file contains the complete song title but the file has a truncated/abbreviated name, this is displeasing to my perfectionist eye! I wrote a second program which, when pointed at a folder, looks at every .m4a file in it and all sub-folders it contains, and reads the song name from the file then renames the file appropriately (given that the file system I use may contain very long names and replacing any invalid characters). This required two fairly difficult (for a beginner) sub-tasks—one was to recursively inspect all sub-directories the other was to parse the meta-data in an MP4 (.m4a) file.

tag2file.zip

Years ago I knew how to post code projects on my web page (different OS!) I may be able to figure out how to zip up a project and post it on my website, but what do I need to include, to make the offering useful? I have downloaded tons of code examples and not a single one would compile! Sometimes the code itself was worth reading, but I would like folks to be able to compile and run my examples. I will try zipping the project folder and sticking that on my site.

...you can share them and make communities around them too at http://codeplex.com

I had not found codeplex--looks like a good resource for both mining and posting code. Thanks!

and what about http://sourceforge.net/ ?

I'm a member at Sourceforge but do not find it user friendly. For me, as a seeker of sample code, not a single one of at least 15 VB.Net project I got there would compile and run! I think the major changes in VB2008 are the culprits :) !

I am working on the second project today (tag2file). It is still very rough! Am learning about Try...Catch...Finally. When last I coded (about 8 years ago) they were just showing up and I never really learned the details. Is this proper:

Try
                                My.Computer.FileSystem.RenameFile(fileNameFull, fileNameWext.ToString())
                            Catch Ex As ArgumentException
                            Catch Ex As FileNotFoundException
                            Catch Ex As PathTooLongException
                            Catch Ex As IOException
                            Catch Ex As NotSupportedException
                            Catch Ex As SecurityException
                            Catch Ex As UnauthorizedAccessException
                                MsgBox("Uncaught file rename error. " + Ex.GetType().Name + vbNewLine + "Did NOT rename:" + vbNewLine + fileNameFull)
                            Finally
                                MsgBox("Unknown uncaught file rename error.  Did NOT rename:" + vbNewLine + fileNameFull)
                            End Try

or do I have to catch each seperately with its own MsgBox?

Try...End Try

or do I have to catch each seperately with its own MsgBox?

Ah, now I see! If I want a generic "catch all" I use:

Try
            ...
        Catch exp As Exception
            MsgBox("An error occurred while attempting to load a file. The error is:" + System.Environment.NewLine + exp.ToString() + System.Environment.NewLine)
        End Try

You've to. and don't write catch code in Finally (because finally code executed in all cases)

Try...End Try

or do I have to catch each seperately with its own MsgBox?

Ah, now I see! If I want a generic "catch all" I use:

Try
      ...
Catch exp As Exception
    MsgBox("An error occurred while attempting to load a file. The error is:" + System.Environment.NewLine + _
        exp.ToString() + System.Environment.NewLine)
End Try

You've to. and don't write catch code in Finally (because finally code executed in all cases)

Ah, " finally code executed in all cases" that was very helpful info!

Exactly and in .net 2.0 and later you can write

'try block
catch..
catch..
catch..

without need to use nested try catch

Exactly and in .net 2.0 and later you can write

'try block
catch..
catch..
catch..

without need to use nested try catch

I will need a concrete example to understaand that.

http://msdn.com enjoy a lot of examples and explanation...

That's at the top of my favorites and always open while I code!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.