Saturday 5 September 2015

VBScript Objects in FileSystemObject


VBScript Objects in FileSystemObject

The FileSystemObject is used to gain access to a computer's file system. It can create new files and access existing ones.

Examples

Code:
<% 
dim filesys, filetxt, getname, path 
Set filesys = CreateObject("Scripting.FileSystemObject") 
Set filetxt = filesys.CreateTextFile("c:\somefile.txt", True) 
path = filesys.GetAbsolutePathName("c:\somefile.txt") 
getname = filesys.GetFileName(path) 
filetxt.WriteLine("Your text goes here.") 
filetxt.Close 
If filesys.FileExists(path) Then 
Response.Write ("Your file, '" getname "', has been created.") 
End If 
%>
Output:
"Your file, 'somefile.txt', has been created."
Explanation:
This code uses the CreateTextFile method of the FileSystemObject object to create a text file (c:\somefile.txt) and then writes some text to it.

Properties

Drives
Syntax: drvcollection = ] object.Drives
Returns a Drives collection consisting of all the Drive objects on a computer.

Methods

BuildPath
Syntax: [newfullpath = ]object.BuildPath(path, name)
This method is used to append a name onto an existing path.
CopyFile
Syntax: object.CopyFile source, destination [,overwrite]
This method allows us to copy one or more files from one location (the source) to another (destination).
CopyFolder
Syntax: object.CopyFolder source, destination [, overwrite]
Copies one or more folders and all contents, including files and subfolders, from one location to another.
CreateFolder
Syntax: object.CreateFolder (foldername)
This method allows us to create a folder with the specified foldername.
CreateTextFile
Syntax: object.CreateTextFile filename [,overwrite[, unicode]]
Creates a text file and returns a TextStreamObject that can then be used to write to and read from the file.
DeleteFile
Syntax: object.DeleteFile file [,force]
This method deletes a specified file or files (using wilcards).
DeleteFolder
Syntax: object.DeleteFolder folder [,force]
This method deletes a specified folder, including all files and subfolders.
DriveExists
Syntax: object.DriveExists(drive)
This method lets us check if a specified drive exists. It returns True if the drive does exist and False if it doesn't.
FileExists
Syntax: object.FileExists(file)
Lets us check whether a specified file exists. Returns True if the file does exist and False otherwise.
FolderExists
Syntax: object.FolderExists(folder)
Allows us to check if a specified folder exists. Returns True if the folder does exist and False if it doesn't.
GetAbsolutePathName
Syntax: object.GetAbsolutePathName(path)
This method gets the complete path from the root of the drive for the specified path string.
GetBaseName
Syntax: object.GetBaseName(path)
This method gets the base name of the file or folder in a specified path.
GetDrive
Syntax: object.GetDrive(drivename)
This method returns a Drive object corresponding to the drive in a supplied path.
GetDriveName
Syntax: object.GetDriveName(path)
This method gets a string containing the name of the drive in a supplied path.
GetExtensionName
Syntax: object.GetExtensionName(path)
Used to return a string containing the extension name of the last component in a supplied path.
GetFile
Syntax: object.GetFile (filename)
Returns the File object for the specified file name.
GetFileName
Syntax: object.GetFileName(path)
This method is used to return the name of the last file or folder of the supplied path.
GetFileVersion
Syntax: object.GetFileVersion(path)
This method is used to return the version of the file in the specified path.
GetFolder
Syntax: object.GetFolder (foldername)
This method returns a Folder object of the folder specified in the folder parameter.
GetParentFolderName
Syntax: object.GetParentFolderName(path)
Returns a string containing the name of the parent folder of the last file or folder in a specified path.
GetSpecialFolder
Syntax: object.GetSpecialFolder (folderid)
Returns the path to one of the special folders - \Windows, \System or \TMP.
GetTempName
Syntax: object.GetTempName
This method is used to generate a random filename for a temporary file.
MoveFile
Syntax: object.MoveFile source, destination
Moves one or more files from one location to another.
MoveFolder
Syntax: object.MoveFolder source, destination
Moves one or more folders from one location to another.
OpenTextFile
Syntax: object.OpenTextFile (filename [, iomode[, create[, format]]])
Opens the file specified in the filename parameter and returns an instance of the TextStreamObject for that file. )

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.

Blog Archive