VBScript: File System Object Examples

1. Show List of drives

Dim oFS, colDrives, d, sDrvLst
Set oFS = CreateObject("Scripting.FileSystemObject")
Set colDrives = oFS.Drives
sDrvLst = ""
For each d in colDrives
sDrvLst = sDrvLst & d.driveLetter & " ( "
If d.IsReady Then
sDrvLst = sDrvLst & d.VolumeName & ")"
End If
sDrvLst = sDrvLst & vbCrLf
Next
MsgBox sDrvLst


2. Copy Files
Dim oFS, sFile_Source, sFile_Dest
Set oFS = CreateObject("Scripting.FileSystemObject")
sFile_Source = InputBox("Enter source file address")
sFile_Dest = InputBox("Enter destination file address")
oFS.CopyFile(sFile_Source, sFile_Dest, 0) ' 0 - Do not overwrite

No comments:

Post a Comment

Thank you for commenting. Please keep visiting.