Visual Basic 6 File System Objects
by Paul Lomax


Listing One
Dim oOFS As FileSystemObject
Dim oDrive As Drive
Set oOFS = New FileSystemObject
    Set oDrive = oOFS.GetDrive("\\NTWS3\C$")

Listing Two
Dim oFSO As FileSystemObject
Dim oFolder As Folder
    Set oFSO = New FileSystemObject
        Set oFolder = oFSO.GetSpecialFolder(SystemFolder)

Listing Three
Dim oFSO As FileSystemObject
          Set oFSO = New FileSystemObject

Listing Four
Dim oFSO As FileSystemObject
Dim oFolder As Folder
    Set oFSO = New FileSystemObject
    oFSO.MoveFolder("C:\Program Files\Data\", "C:\Archives\")

Listing Five
Dim oFSO As FileSystemObject
Dim oFolder As Folder
    Set oFSO = New FileSystemObject
        Set oFolder = oFSO.GetFolder("C:\Program Files\Data\")

Listing Six
Dim oFSO As FileSystemObject
Set oFSO = New FileSystemObject
    If Not oFSO.FileExists("d:\datafiles\newdata.dat") Then
        MsgBox "The new data file cannot be found"
    End If

Listing Seven
Dim oFSO As FileSystemObject
Dim oDrive As Drive
Set oFSO = New FileSystemObject
    Set oDrive = oFSO.GetDrive("\\NTWS3\E$")
        If oDrive.DriveType = CDRom Then
            MsgBox "Sorry - can't write to this drive"
        End If

Listing Eight
Dim oFSO As FileSystemObject
Dim oDrive As Drive
Dim oFolder As Folder
Set oFSO = New FileSystemObject
    Set oDrive = oFSO.GetDrive("\\NTWS3\C$")
        Set oFolder = oDrive.RootFolder

Listing Nine
Dim oFSO As FileSystemObject
Dim oDrive As Drive
Dim oFolder As Folder
Dim oFolders As Folders
Set oFSO = New FileSystemObject
    Set oDrive = oFSO.GetDrive("\\NTWS3\C$")
        Set oFolder = oDrive.RootFolder
            Set oFolders = oFolder.SubFolders

Listing Ten
Dim oFSO As FileSystemObject
Dim oDrive As Drive
Dim oFolder As Folder
Dim oFiles As Files
Set oFSO = New FileSystemObject
    Set oDrive = oFSO.GetDrive("\\NTWS3\C$")
        Set oFolder = oDrive.RootFolder
            Set oFiles = oFolder.Files

Listing Eleven
Dim oFSO As FileSystemObject
Dim oTextStream As TextStream
Set oFSO = New FileSystemObject
    Set oTextStream = oFSO.CreateTextFile("newfile.txt")

Listing Twelve
Dim oFSO As FileSystemObject
Dim oTextStream As TextStream
Set oFSO = New FileSystemObject
  Set oTextStream = oFSO.OpenTextFile("newfile.txt",ForWriting, Create:=True)

Listing Thirteen
Dim oFSO As FileSystemObject
Dim oFile As File
  Set oFSO = New FileSystemObject
     Set oFile = oFSO.GetFile("c:\data\olddata.dat")
        Debug.Print oFile.DateLastModified

Listing Fourteen 
Dim oFSO As FileSystemObject
Dim oTextFile As TextStream
Dim sIncomingData As String
 Set oFSO = New FileSystemObject
   Set oTextFile = oFSO.OpenTextFile("c:\data\textdata.txt", ForReading)
      sIncomingData = oTextFile.Read(100)

Listing Fifteen
Dim oFSO As FileSystemObject
Dim oTextFile As TextStream
Dim sOutgoingData As String
  sOutgoingData = "Some Text"
   Set oFSO = New FileSystemObject
     Set oTextFile = oFSO.OpenTextFile("c:\data\textdata.txt", ForAppending)
       oTextFile.WriteLine sOutgoingData


6


