Accessing Special Directories with System.Environment

Private Sub SpecialFolders()
   Dim mydocs, mymusic, mypics As String

   mydocs = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)

   mymusic = System.Environment.GetFolderPath(Environment.SpecialFolder.MyMusic)

   mypics = System.Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)

  Console.WriteLine(mydocs)
  Console.WriteLine(mymusic)
  Console.WriteLine(mypics)
End Sub
    
Output:

C:\Users\John\Documents
C:\Users\John\Music
C:\Users\John\Pictures
Here we are using System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) to access certain commonly used folders. The input parameter is an Enum type integer.

The strong point about using Envirnoment to access special folders is that Environment provides access to most, if not all special directories.
Accessing Special Directories with Microsoft.VisualBasic.FileIO

Private Sub SpecialDirectories()
  Dim MyDocs, CurrentUsr, MyMusic, MyPics, TempFile As String

  MyDocs = Microsoft.VisualBasic.FileIO.SpecialDirectories.MyDocuments
  Console.WriteLine(MyDocs)

  CurrentUsr = Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData
  Console.WriteLine(CurrentUsr)

  MyMusic = Microsoft.VisualBasic.FileIO.SpecialDirectories.MyMusic
  Console.WriteLine(MyMusic)

  MyPics = Microsoft.VisualBasic.FileIO.SpecialDirectories.MyPictures
  Console.WriteLine(MyPics)

  TempFile = Microsoft.VisualBasic.FileIO.SpecialDirectories.Temp
  Console.WriteLine(TempFile)

End Sub



Output:
C:\Users\John\Documents
C:\Users\John\AppData\Roaming\PathWorks\PathWorks\1.0.0.0
C:\Users\John\Music
C:\Users\John\Pictures
C:\Users\John\AppData\Local\Temp

VisualBasic.FileIO.SpecialDirectories provides access to just a few special directories. It provides access to the Temp directory, which Environment does not.
Accessing the current directory- 3 ways
Private Sub CurDir()

  Dim dircurrentdir,envcurrentdir,vbfcurrentdir As String 
       
  dircurrentdir = System.IO.Directory.GetCurrentDirectory
  envcurrentdir = System.Environment.CurrentDirectory
  vbfcurrentdir = Microsoft.VisualBasic.FileIO.FileSystem.CurrentDirectory
 ' they are all the same, take your pick

End Sub
Sometimes you need the current directory., Here are three ways to get it. They are all exactly the same. If your are in the development environment it yields the \bin\Debug directory in your current project.






































































































600

1200

1800

2400

3000

3600

4200

4800

5400

6000

6600

7200

7800

8400

9000

9600

10200

10800

11400

12000

12600

13200

13800

14400

15000

15600

16200

16800

17400

18000

18600

19200

19800

20400

11/24/2015
TheLonelyProgrammer.Net
Alone in a sea of non-programmers
Home File Copy Path List Drives List Files Special Folders Accessing and changing file times