ASP Getting Started Tutorials-folder actions

Source: Internet
Author: User

Folder operations mainly include creating, copying, moving, and deleting folders, checking the existence of folders, and specifying the corresponding file objects in a folder in the path. You can do this by using the Filesystemobjec object or the method of the Folder object.

One, use the FileSystemObject object's corresponding method to carry on the operation of the folder

1. When you create a folder using the FileSystemObject object, you create the FileSystemObject object first, and then use its CreateFolder method to create the folder object, which has the following syntax format:

fso.CreateFolder(foldername)

The Parameter object specifies the name of the FileSystemObject object. FolderName is a string expression that specifies the folder you want to create.

2, copy folder: Copy one or more folders to another location, the syntax format is as follows:

<% fso.CopyFolder source,destination[,overwrite] %>

* FSO: Specifies the name of the FileSystemObject object;

* Source: A string representing the specified source folder, which can have wildcards when copying one or more folders;

* Destination: A string representing the destination, copying the folder from source to that location, and not allowing wildcard characters;

* Overwrite: is an optional parameter, Boolean value indicating whether to overwrite the existing folder: if it is True (the default value), overwrite, if False, not overwritten.

Note:

* Wildcard characters can only be used in the last part of the path of the Source parameter.

* If destination does not exist, copy the Source folder and all its contents;

* If destination is a folder that already exists, an error occurs;

* If destination is a directory, copy the folder and all of its contents. If the file you want source contains is already stored in destination, and overwrite is false, an error occurs, otherwise the file is copied to overwrite the existing file.

* If destination is a read-only directory, an error occurs when the existing gratifying read file is copied to the directory and overwrite is false. ;

* If source uses wildcard characters, but there is no matching file, there will be an error;

* The CopyFolder method stops when it encounters the first error that occurs. This method does not undo any changes that were made before the error occurred.

3. Move folder: Move one or more folders from one location to another, in the following syntax format:

<% fso.MoveFolder source,destination %>

* FSO: Specifies the name of the FileSystemObject object;

* Source: Specifies the path to the folder you want to move, which can only be used with wildcards in the last part of the path;

* Destination: Specifies a path that indicates that you want to move the folder to that target location, which cannot contain wildcards.

Note:

* If the destination does not exist, move the folder;

* If destination is a folder that already exists, an error occurs;

* If the destination is a directory, an error occurs;

* If source uses wildcard characters but no matching files, an error occurs;

* The MoveFolder method stops when it encounters the first error that occurs. This method does not undo any changes that were made before the error occurred.

4, delete folder: Delete the specified folder, the syntax format is as follows:

<% fso.DeleteFolder filespec[.force]

* FSO: Specifies the name of the FileSystemObject object;

* filespec Specifies the name of the folder to be deleted, and the wildcard character can be included in the last part of the path;

* Force: is an optional parameter, Boolean value, True if you want to delete a read-only folder, or False (default).;

* If no matching file is found, an error occurs. The DeleteFile method stops when it encounters the first error that occurs. This method does not undo any changes that were made before the error occurred.

5, check the existence of the specified folder, if the folder exists, then return True, otherwise return False. The syntax format is as follows:

<% object.FolderExists(folderspec) %>

6. Use the GetFolder method to return a folder object corresponding to a file in the specified path. The syntax format is as follows:

<% object.GetFolder(folderspec)

object specifies the name of the FileSystemObject, folderspec the path to the specified folder. If the specified folder does not exist, an error occurs.

7. Use the Getparentfoldername method to return a string containing the parent folder of the last file or folder in the specified path. The syntax format is as follows:

object.GetParentFolderFolderName(Path)

Path to specify the name of the parent folder to return the file or folder to. If the Getparentfoldername method returns a 0-length string (' "). In addition, the Getparentfolder method can only work on the provided Path string. It cannot attempt to parse a path, nor can it check whether the specified path exists.

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.