JavaScript Scripting FileSystemObject works on client side that provides the functionality to access the file system of client’s machine. Using fso i.e. FileSystemObject you can perform various actions on the files system of client machine but provided that the client’s web browser allows the JavaScript automation server to create the object. Functionality of FileSystemObject is only possible if the web browser of client’s PC has very low security. Low security means web browser allows creating the Javascript signed or unsigned activeX objects that could access the client’s machine. So if you are using a FileSystemObject through Javascript ActiveXObject method then it doesn’t mean that you can do any action on client’s machine very easily.
Javascript Scripting FileSystemObject Properties and Methods
Following are the properties and methods of FileSystemObject that allows you to access the files and folders at the client side:
Property
1. Drives: Javascript FileSystemObject allows the access of only 1 object after its initialization. Drives property returns the collection of drives on the client’s PC.
Further methods of FSO allow the use of different types of properties associated with files such as attributes, DateCreated, DateLastAccessed etc.
Methods
- BuildPath: Builds a complete path by concatenating two parameter values such Path and Name.
- CopyFile: Copies files from source to the destination path. Also allows you to overwrite the existing file.
- CopyFolder: Copies folder from source to the destination path. It also allows you to overwrite the destination folder if it already exists.
- CreateFolder: Creates a new folder with specified name at the specified location.
- CreateTextFile: Creates a text file at the specified location with given name and returns TextStream. This TextStream resultant further provides its own properties and methods that allow you to read and write text in the newly created file.
- DeleteFile: Deletes the file at the specified location.
- DeleteFolder: Deletes the folder at the specified path along with its contents.
- DriveExists: Checks the Drive whether it exists or not and returns the Boolean result.
- FileExists: Checks the file whether it exists at the specified location and returns the Boolean result.
- FolderExists: Checks the folder whether it exists at the specified location and returns the Boolean result.
- GetAbsolutePathName: Returns the absolute path of the specified file or folder.
- GetBaseName: Returns the base of file or folder from the specified path. If path contains filename then it returns the filename without file extension.
- GetDrive: Accepts the name of the drive as its letter such as C,D,E that exists on the client’s PC and allows the access to properties of Drive such e.g.: AvailableSpace, DriveType, FileSystem etc.
- GetDriveName: Returns the drive letter from the specified path.
- GetExtensionName: Returns the extension of file specified in the path.
- GetFile: Returns a file object for the specified file path and allows the access to its properties such as DateCreated, DateLastAccessed etc.
- GetFileName: Return the file name with extension from the specified path.
- GetFolder: Returns a folder object for the specified file path and allows the access to its properties such as DateCreated, DateLastAccessed, Files etc.
- GetParentFolderName: Returns the parent folder name for the specified file or folder that is nearest to the file name in the location path.
- GetSpecialFolder: It returns the path to the special folder of window such as Temporary files folder, system32 folder etc.
- GetTempName: Return the temporary name for a file that can used to save the temporary data in the client’s PC. This method returns the randomly generated file names e.g.: rad79FF.tmp
- MoveFile: It provides the functionality to move the file from source to destination path.
- MoveFolder: It provides the functionality to move the folder from source to destination path.
- OpenTextFile: This method of FileSystemObject returns the TextStream for the specified file that can be altered using its accessible functions and properties.
Continue to next tutorial: How to Create FileSystemObject in Javascript to learn about creating the ActiveX object for working with client side files.