JavaScript FSO Properties Daquan

Source: Internet
Author: User
Tags install window naming convention

What is FSO?
FSO, the file system object, is a list of Windows disk directories and files that are removed, created, copied, cut, moved, and manipulated in directories and files. The advantages of using the FSO website: directly read the directory files and subdirectories, easy to maintain, if you need to add any content, put the file in the appropriate directory; FSO website is similar to the Windows interface, easy to use, will use Windows will use the FSO website.
Just imagine, it is very convenient to make your hard disk files and folders into a website, and in the future as long as the content added to the directory can be updated, this is not very convenient? In this way, inexperienced novice can also build their own website.
( article is very long, suitable for learning is not suitable for copying code, example code can see: http://www.cnblogs.com/chuyuan/p/4829447.html)

FSO Properties, directories and files with

AtEndOfLine Property
Returns True if the file pointer is positioned exactly before the end tag in the TextStream file, or False if none.
AtEndOfStream Property
Returns True if the file pointer is at the end of the TextStream file, or False if it is not.
Attributes Property
Sets or returns the properties of a file or folder.
AvailableSpace Property
Returns the amount of space available to the user on the specified drive or network share.
Column Property
Returns the column number of the current character position in the TextStream file.
CompareMode Property
Sets and returns a comparison mode that is used to compare string keywords in a Dictionary object.
Count Property
Returns the number of items in a collection or Dictionary object.
DateCreated Property
Returns the date and time when the specified file or folder was created. Read-only.
Datelastaccessed Property
Returns the date and time that the specified file or folder was last visited.
DateLastModified Property
Returns the date and time that the specified file or folder was last modified.
Drive Property
Returns the letter of the drive that contains the specified file or folder.
DriveLetter Property
Returns the drive letter for the local physical drive or network share.
Drives Property
Returns a Drives collection that contains all the drive objects available on the local computer.
DriveType Property
Returns a value that indicates the type of drive specified.
Files Property
Returns a Files collection that contains all the file objects contained in the specified folder, including those that are set as hidden and System file properties.
FileSystem Property
Returns the type of file system used by the specified drive.
FreeSpace Property
Returns the amount of space available to the user on the specified drive or network share.
IsReady Property
Returns True if the specified drive is ready, or False if not.
IsRootFolder Property
Returns True if the specified folder is the root folder, or False if it is not.
Item Property
Sets or returns the corresponding item for the specified keyword in the Dictionary object. For a collection, returns an item based on the specified keyword.
Key Property
Sets the keywords in the Dictionary object.
Line Properties
Returns the current line number in the TextStream file.
Name Property
Sets or returns the name of the specified file or folder.
ParentFolder Property
Returns the Folder object at the top level of the specified file or folder.
Path Property
Returns the path to the specified file, folder, or drive.
RootFolder Property
Returns a Folder object that represents the root folder of the specified drive.
SerialNumber Property
Returns a decimal sequence number used to uniquely identify a disk volume.
ShareName Property
Returns the network share name for the specified drive.
ShortName Property
Returns the short name used by a program that requires an earlier 8.3 naming convention.
ShortPath Property
Returns the short path used by a program that requires an earlier 8.3 naming convention.
Size Property
Returns the size of the specified file, in bytes, for the file. For a folder, returns the size, in bytes, of all the files and subfolders that the folder contains.
Subfolders Property
Returns a Folders collection that contains all the folders in the specified folder, including those that are set as hidden and System file properties.
TotalSize Property
Returns the total space, in bytes, of a drive or network share.
Type Property
Returns information about the type of file or folder.
VolumeName Property
Sets or returns the volume name of the specified drive.
Method or Property Description
BuildPath () generates a file path
CopyFile () Copying files
CopyFolder () Copy directory
CreateFolder () Create a new directory
CreateTextFile () Generate a file
DeleteFile () Delete a file
DeleteFolder () Delete a directory
Driveexists () Verify that the drive letter is present
Drives returns a collection of drive characters
FileExists () Verify that the file exists
FolderExists checking if a directory exists
Getabsolutepathname () get an absolute path to a file
Getbasename () Get file name
Getdrive () get the drive letter name
GetDriveName () get the drive letter name
Getextensionname () Get the suffix of the file
GetFile () Generate File Object
GetFileName () Get file name
GetFolder () Get directory Object
Getparentfoldername gets the parent directory name of the file or directory
GetSpecialFolder () Get a special directory name
GetTempName () generates a temporary file object
MoveFile () Moving files
MoveFolder () Move directory
OpenTextFile () open a file stream

Example Description FSO Usage
BuildPath (path, file name)//This method adds a file to the given path and automatically adds a delimiter
<script language= "JavaScript" >
<!--
var fso = new ActiveXObject ("Scripting.FileSystemObject");
var NewPath = fso. BuildPath ("C:\\tmp", "51js.txt"); Path to generate C:\tmp\51js.txt
alert (NewPath);
-
</SCRIPT>

CopyFile (source file, target file, overwrite)//copy source file to target file, when overwrite value is true, overwrite file if destination file exists
<script language= "JavaScript" >
<!--
var fso = new ActiveXObject ("Scripting.FileSystemObject");
var NewPath = fso. CopyFile ("C:\\autoexec.bat", "D:\\autoexec.bak");
-
</SCRIPT>

CopyFolder (object directory, target directory, overwrite)//Copy the object directory to the target directory, when overwrite is true, if the target directory exists will overwrite the file
<script language= "JavaScript" >
<!--
var fso = new ActiveXObject ("Scripting.FileSystemObject");
Fso. CopyFolder ("C:\\windows\\desktop", "d:\\"); Copy the Desktop directory of the C drive to the root of the D drive
-
</SCRIPT>

CreateFolder (directory name)//Create a new directory
<script language= "JavaScript" >
<!--
var fso = new ActiveXObject ("Scripting.FileSystemObject");
var newfoldername = fso. CreateFolder ("C:\\51js"); Create a 51JS directory on the C drive
-
</SCRIPT>

CreateTextFile (file name, overwrite)//Create a new file, if this file already exists, you need to set the override value to True
<script language= "JavaScript" >
<!--
var fso = new ActiveXObject ("Scripting.FileSystemObject");
var newfileobject = fso. CreateTextFile ("C:\\autoexec51js.bat", true); The script will create a file called Autoexec51js.bat in the C drive.
-
</SCRIPT>

DeleteFile (file name, read-only?) )//Delete a file, if the file's properties are read-only, you need to set the read-only value to True
<script language= "JavaScript" >
<!--
var fso = new ActiveXObject ("Scripting.FileSystemObject"); To be safe, I'm going to back up the Autoexec.bat I want to remove to your D drive.
var NewPath = fso. CopyFile ("C:\\autoexec.bat", "D:\\autoexec.bat"); Remove the Autoexec.bat file from the C drive.
Fso. DeleteFile ("C:\\autoexec.bat", true);
-
</SCRIPT>

DeleteFolder (file name, read-only?) //Delete a directory, if the directory's properties are read-only, you need to set the read-only value to True
<script language= "JavaScript" >
<!--
var fso = new ActiveXObject ("Scripting.FileSystemObject");
Fso. CopyFolder ("C:\\windows\\desktop", "d:\\"); For security, I'll start by copying your C-drive desktop directory to the root of your D-drive.
Fso. DeleteFolder ("C:\\windows\\desktop", true); Remove your desktop directory, but because desktop is something of the system, it can't be deleted all, but ...
-
</SCRIPT>

Driveexists (drive letter)//check whether a disk exists, if it exists, return to true, does not exist on the back ....
<script language= "JavaScript" >
<!--
var fso = new ActiveXObject ("Scripting.FileSystemObject");
hasdrived = fso. Driveexists ("D"); Check if the system has a D disk present
Hasdrivez = fso. Driveexists ("Z"); Check if the system has a Z disk present
if (hasdrived) alert ("There is a D-disk in your system");
if (!hasdrivez) alert ("There is no Z-disk in your system");
-
</SCRIPT>

FileExists (file name)//Check whether a file exists, if it exists, return to true, does not exist ....
<script language= "JavaScript" >
<!--
var fso = new ActiveXObject ("Scripting.FileSystemObject");
FileName = fso. FileExists ("C:\\autoexec.bat");
if (fileName) alert ("You have a Autoexec.bat file in the C drive, press OK after this file will be deleted!") "); A joke:)
-
</SCRIPT>

FolderExists (directory name)//check whether a directory exists, if it exists, it will be true, does not exist to return ....
<script language= "JavaScript" >
<!--
var fso = new ActiveXObject ("Scripting.FileSystemObject");
FolderName = fso. FolderExists ("c:\\windows\\fonts");
if (folderName) alert ("Press OK after the system's font will be deleted!") "); A joke:)
-
</SCRIPT>

Getabsolutepathname (File object)//returns the absolute path of the file object in the system
<script language= "JavaScript" >
<!--
var fso = new ActiveXObject ("Scripting.FileSystemObject");
PathName = fso. Getabsolutepathname ("C:\\autoexec.bat");
alert (pathName);
-
</SCRIPT>

Getbasename (File object)//Return file name of the object
<script language= "JavaScript" >
<!--
var fso = new ActiveXObject ("Scripting.FileSystemObject");
BaseName = fso. Getbasename ("C:\\autoexec.bat"); Gets the filename of the Autoexec.bat AutoExec
alert (baseName);
-
</SCRIPT>

Getextensionname (File object)//suffix of file
<script language= "JavaScript" >
<!--
var fso = new ActiveXObject ("Scripting.FileSystemObject");
Exname = fso. Getextensionname ("C:\\autoexec.bat"); Get Autoexec.bat suffix Bat
alert (exname);
-
</SCRIPT>

Getparentfoldername (File object)//Get directory name of Parent
<script language= "JavaScript" >
<!--
var fso = new ActiveXObject ("Scripting.FileSystemObject");
ParentName = fso. Getparentfoldername ("C:\\autoexec.bat"); Get Autoexec.bat's parent directory C-Disk
alert (ParentName);
-
</SCRIPT>

GetSpecialFolder (Directory code)//Get some special directories in the system path, directory code 3 is 0: Install window Directory 1: System files directory 2: Temp file directory
<script language= "JavaScript" >
<!--
var fso = new ActiveXObject ("Scripting.FileSystemObject");
Tmpfolder = fso. GetSpecialFolder (2); Get the path to the system temp file directory as mine is C:\windows\temp
alert (Tmpfolder);
-
</SCRIPT>

GetTempName ()///Generate a random temporary file object, followed by a number of random numbers in the RAD lead, as if some software is generated during installation *.tmp
<script language= "JavaScript" >
<!--
var fso = new ActiveXObject ("Scripting.FileSystemObject");
Tmpname = fso. GetTempName (); I built the raddb70e.tmp when I tested it.
alert (tmpname);
-
</SCRIPT>

MoveFile (source file, destination file)//move the source file to the location of the destination file
<script language= "JavaScript" >
<!--
var fso = new ActiveXObject ("Scripting.FileSystemObject");
var NewPath = fso. MoveFile ("C:\\autoexec.bat", "D:\\autoexec.bat"); Move the C-drive Autoexec.bat file to the D drive.
-
</SCRIPT>

JavaScript FSO Properties Daquan

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.