File System

Modified on 2010/02/24 22:02 by Administrator — Categorized as: Uncategorized

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:

void CopyFile(String sourceFilePath, String destFilePath )

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:

void CopyFile(String sourceFilePath, String destFilePath, Boolean overwrite)

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:

void MoveFile(String sourceFilePath, String destFilePath )

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:

Boolean FileExists(String filePath )

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:

void DeleteFile(String filePath )

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:

void CreateDirectory(String path )

Parameters:

path: The directory path to create.

Example:


FileSystem.CreateDirectory( @"c:\newdirectory" );

DirectoryExists

Determines whether the specified directory exists.

Syntax:

Boolean DirectoryExists(String directoryPath )

Parameters:

directoryPath: The path of the directory to check.

Example:


b = FileSystem.DirectoryExists( @"c:\file.txt" );

DeleteDirectory ( String )

Deletes the specified directory.

Syntax:

void DeleteDirectory(String directoryPath )

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:

void DeleteDirectory(String directoryPath, Boolean recursive )

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

TextFileReader Object
TextFileWriter Object
Scripting