Work with Drives, Folders and Files.
Object heirarchy: FileSystemObject FileSystemObject.Drives FileSystemObject.Drives.item FileSystemObject.GetFolder
FileSystemObject.GetFile
Once a File System Object has been opened you can use Methods and Properties to work with folders and files:
FileSystemObject Methods:
.BuildPath(strPath, strFileName) .CopyFile(Source, Dest [,Overwrite (True/False)] .CopyFolder(Source, Dest [,Overwrite (True/False)] .CreateFolder(Path) .CreateTextFile(FileName [,Overwrite (True/False) [, Unicode (True/False)]]) .DeleteFile(FileSpec, Force (True/False)) .DeleteFolder(FileSpec, Force (True/False)) .DriveExists(strDrive) (True/False) .FileExists(strFile) (True/False) .FolderExists(strFolder) (True/False) .GetAbsolutePathName(strPath) - Returns a string with the full drive, path, and file names: Drive:\Path\To\File.Ext .GetBaseName(strPath) - Returns a string with the file name, without the extension: File .GetDrive(strDrive) - Returns an object referring to a drive .GetDriveName(strDrive) - Returns a string referring to a drive. Drive: .GetExtensionName(strPath) - Returns a string referring to the extension of the file. Ext .GetFile(strPath) - Returns an object referring to a file. .GetFileName(strPath) - Returns a string referring to a file. File.Ext .GetFolder(strPath) - Returns an object referring to the path. .GetParentFolderName(strPath) - Returns a string referring to the path. \Path\To\ .GetSpecialFolderName(FolderType) FolderType=SystemFolder/TemporaryFolder/WindowsFolder .GetStandardStream(Type [,Unicode (True/False)]) .GetTempName() .MoveFile(Source, Dest) .MoveFolder(Source, Dest) .OpenTextFile(strFile [,IOMode (8=append, 1=Read, 2=Write) [,Create (True/False) [,Format (0=Ascii, -1=Unicode, -2=default)]]])
Drive Properties:
AvailableSpace, DriveLetter, DriveType, FileSystem, FreeSpace,IsReady, Path, RootFolder, SerialNumber, ShareName, TotalSize, VolumeName
DrivesCollection properties: Count, Item
File Properties:
Attributes, DateCreated, DateLastAccessed, DateLastModified,Drive,
Name, ParentFolder, Path, ShortName, ShortPath, Size, Type
File Methods: .copy, .Delete, .Move, .OpenAsTextStream
Folder Properties:
Attributes, DateCreated, DateLastAccessed, DateLastModified,Drive,
Files, IsRootFolder, Name, ParentFolder, Path,
ShortName, ShortPath, Size, SubFolders, Type
Folder Methods: .copy, .CreateTextFile, .Delete, .Move
FoldersCollection properties: Count, Item
FoldersCollection Methods: Add
Examples
Create a text file:
Dim objFS, objFile
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFile = objFS.CreateTextFile("C:\work\demo.txt")
objFile.WriteLine("some sample text")
Open an existing file:
Dim objFS, objFile Set objFS = CreateObject("Scripting.FileSystemObject") Set objFile = objFS.GetFile("C:\Work\Sample.xls") WScript.Echo objFile.DateCreated & objFile.Name
Check drive space:
Dim objFS, objDrive, objDriveCount Set objFS = CreateObject("Scripting.FileSystemObject") Set objDriveCount = objFS.Drives Set objDrive = objFS.Drives("C") WScript.Echo objDriveCount & " Free Space " & objDrive.AvailableSpace
“Is not the whole world a vast house of assignation of which the filing system has been lost?” ~ Quentin Crisp
Related:
.ReadLine - Accept user text input
Syntax - error codes
.MapNetworkDrive - Drive Map
Equivalent PowerShell cmdlet: Get-Item / Get-ChildItem