Provides static methods for common file system operations. This object can not be instantiated in a script.
Accessing files and directories is done under the context of the user that the application or service is running under. This can cause some file permissions/access rights issues if the file does not allow access to that user.
Static Methods
CopyFile ( String, String )
Copies an existing file to a new one.
Syntax:Parameters:sourceFilePath: The path of the file to copy.
destFilePath: The destination file path.
Example:
FileSystem.CopyFile( @"c:\oldfile.txt", @"c:\oldfile_backup.txt" );
CopyFile ( String, String, Boolean )
Copies an existing file to a new one. Overwriting a file of the same name is allowed.
Syntax:Parameters:sourceFilePath: The path of the file to copy.
destFilePath: The destination file path.
overwrite: true if the destination file can be overwritten, otherwise false.
Example:
FileSystem.CopyFile( @"c:\oldfile.txt", @"c:\oldfile_backup.txt", true );
MoveFile
Moves an existing file to a new location, providing the option to specify a new filename.
Syntax:Parameters:sourceFilePath: The path of the file to move.
destFilePath: The new path for the file.
Example:
FileSystem.MoveFile( @"c:\file.txt", @"c:\oldfile.txt" );
FileExists
Determines whether the specified file exists.
Syntax:Parameters:filePath: The path of the file to check.
Example:
b = FileSystem.FileExists( @"c:\file.txt" );
DeleteFile
Deletes the specified file. An error will not occur if the specified file does not exist.
Syntax:Parameters:filePath: The path of the file to delete.
Example:
FileSystem.DeleteFile( @"c:\file.txt" );
CreateDirectory
Creates all the directories in the specified path.
Syntax:Parameters:path: The directory path to create.
Example:
FileSystem.CreateDirectory( @"c:\newdirectory" );
DirectoryExists
Determines whether the specified directory exists.
Syntax:Parameters:directoryPath: The path of the directory to check.
Example:
b = FileSystem.DirectoryExists( @"c:\file.txt" );
DeleteDirectory ( String )
Deletes the specified directory.
Syntax:Parameters:directoryPath: The path of the empty directory to delete. The directory must be writable and empty.
Example:
FileSystem.DeleteDirectory( @"c:\newdirectory" );
DeleteDirectory ( String, Boolean )
Deletes the specified directory, and if indicated any subdirectories and files in the path.
Syntax:Parameters:directoryPath: The path of the empty directory to delete.
recursive: true to delete directories, subdirectories, and files in the specified path, false otherwise.
Example:
FileSystem.DeleteDirectory( @"c:\newdirectory", true );
See Also