VB.Net - Special Directories
Whenever you work with drives, directories (folders) or files, you should always use
a Try...Catch...End Try block because there will always be a risk of unexpected errors.
If you allow the user any control over what drive/folder/file is selected, you should also
move all drive/folder/file access into a background worker. It is not reasonable to expect a user
to realise that copying multi-gigabyte files or backing up a primary hard drive could be a slow process.
When acquiring directory names, you will encounter some occassions where the final "\" is included
and others when it is missing. This bit of code suggests one method to ensure consistency
Private Shared Function AddSlash(directory As String) As String
if directory="" then return ""
if directory.Length = 1 then directory &= ":"
If Mid(directory, directory.Length, 1) <> "\" Then directory &= "\"
If you need to find a special/system directory, you can select the appropriate line from the following code.
When working with the system directories, you can encounter folders/files that are locked by Windows
and experience run-time errors. All folder/file access should be protected by a "Try ... End Try"
and pay particular attention to "Catching" the unable to access errors.
Dim directory As String
directory = My.Computer.FileSystem.SpecialDirectories.Desktop
directory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
directory = My.Computer.FileSystem.SpecialDirectories.MyMusic
directory = My.Computer.FileSystem.SpecialDirectories.MyPictures
directory = My.Computer.FileSystem.SpecialDirectories.ProgramFiles
directory = My.Computer.FileSystem.SpecialDirectories.Programs
directory = My.Computer.FileSystem.SpecialDirectories.Temp
DigitalDan.co.uk ... Hits = 75