ASP 3.0 Advanced Programming (21)

Source: Internet
Author: User
Tags date object copy end parent directory reference return root directory
Programming | Advanced 1. Folder Object
The RootFolder property of the driver object returns a Folder object through which all content in the drive can be accessed. You can use the properties and methods of this Folder object to traverse the directory on the drive and get the properties of that folder and other folders.
(1) Properties of the Folder object
A Folder object provides a set of properties that you can use to get more information about the current folder or to change the name of the folder. Its properties and descriptions are shown in table 5-9:
Table 5-9 Properties and descriptions of Folder objects
Property
Description

Attributes
Returns the properties of a folder. Can be one or a combination of the following values: Normal (0), ReadOnly (1), Hidden (2), System (4), Volume (name) (8), Directory (folder) (16), Archive (32), Alias (64 ) and Compressed (128). For example, a hidden read-only file with a value of 3 attributes

DateCreated
Returns the date and time the folder was created

Datelastaccessed
Returns the date and time the folder was last accessed

DateLastModified
Returns the date and time the folder was last modified

Drive
Returns the drive letter of the drive where the folder is located

Files
Returns the Files collection contained in a Folder object that represents all of the file

IsRootFolder
Returns a Boolean value indicating whether the folder is the root folder of the current drive

Name
Sets or returns the name of a folder

ParentFolder
Returns the folder object corresponding to the parent folder

Path
Returns the absolute path to the folder, using the appropriate long file name

ShortName
Returns the DOS-style folder name in 8.3 form

ShortPath
Returns the absolute path of a DOS-style 8.3-form folder

Size
Returns the size of all files and subfolders contained in this folder

Subfolers
Returns the Folders collection for all subfolders contained within the folder, including hidden folders and system folders

Type
If possible, return a description string for a folder (for example, "Recycle Bin")

(2) Method of folder object
The folder object provides a set of methods that can be used to copy, delete, and move the current folder. These methods run the same way as the CopyFolder, Delefolder, and MoveFolder methods of the FileSystemObject object, but these methods do not require the source parameter because the source file is this folder. These methods and descriptions are shown in table 5-10:
Table 5-10 the method and description of Folder object
Method
Description

Copy (Destination,overwrite)
Copy this folder and all the contents to the folder specified by destination. If the end of the destination is a path delimiter (' \ '), the destination is considered to be a folder where the copy folder is placed. Otherwise think destination is the path and name of the new folder you want to create. If the destination folder already exists and the overwrite parameter is set to False, an error is generated and the default overwrite parameter is True

Delete (Force)
Delete the folder and all the contents inside it. If the optional force parameter is set to True, the folder is deleted even if the folder is set to read-only or contains a read-only file. The default force is False

Move (destination)
Move the folder and all of its contents to the folder specified by destination. If the end of the destination is a path delimiter (' \ '), the destination is considered to be a folder where the mobile folder is placed. Otherwise think destination is the path and name of a new folder. An error occurs if the destination folder already exists

CreateTextFile
(Filename,overwrite,unicode)
Creates a new text file in the folder with the specified file name, and returns a corresponding TextStream object. If the optional overwrite parameter is set to True, any existing file of the same name will be overwritten. The default overwrite parameter is False. If the optional Unicode parameter is set to True, the contents of the file are stored as Unicode text. The default Unicode is False

You can use the ParentFolder property of the current folder between folders to return to the parent directory. When a folder is reached, if the IsRootFolder property is true, stop. Leaves the root of the drive, along the directory tree, to traverse or access the specified folder within the Folders collection (returned by the subfolders property of the current folder).
The following program iterates through all the folders in the root directory of drive C and displays information about each folder.
The VBScript procedure is as follows:
' In VBScript:
' Create a FileSystemObject instance
Set objFSO = Server.CreateObject ("Scripting.FileSystemObject")
' Get a reference to drive C
Set Objdrivec = objfso.getdrive ("C:")
' Get a reference to the ' root folder
Set Objroot = Objdrivec.rootfolder
' Get a reference to the subfolders collection
Set objfolders = objroot.subfolders
' Get a reference to the ' subfolders collection
For each objfolder in Objfolders
Set ObjFolder1 = Objfolders.item ((objfolder.name))
Exit for
Next
' Iterate through all of the files in this folder
For each objfile in Objfolder1.files
Response.Write "Name:" & Objfile.name & ""
Response.Write "ShortName:" & Objfile.shortname & ""
Response.Write "Size:" & objfile.size & "bytes"
Response.Write "Type:" & Objfile.type & "<BR>"
Response.Write "Path:" & Objfile.path & ""
Response.Write "ShortPath:" & Objfile.shortpath & "<BR>"
Response.Write "Created:" & objfile.datecreated & ""
Response.Write "LastModified:" & objfile.datelastmodified & "<P>"
Next
The JScript program is as follows:
/



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.