Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
Files have a number of properties that are extremely useful for managing a file system. For example, the DateLastAccessed property tells you the date when someone last opened the file. This property can be used to identify files that are taking up disk space yet are never used. Similarly, the Size property tells you the size of a file in bytes. This helps you to better analyze disk usage; you can tell whether a single file might be using up more than its fair share of storage space.
Traditionally, system administrators have accessed file properties by using either Windows Explorer or command-line tools. Although these tools can return information about the files on a computer, they are not always designed to save this data or to act on it. In addition, many of these tools have only a limited ability to be automated, making it more difficult for system administrators to periodically sweep their hard drives and search for files that meet specific criteria.
Fortunately, detailed information about any file on a computer can also be retrieved by using the FileSystemObject; among other things, this allows you to automate the process of querying the file system for information about a file or group of files. A complete list of properties available through the File object is shown in Table 4.5.
Table 4.5 File Object Properties
Property | Description |
---|---|
Attributes | Bitmap containing the attributes for the file. |
DateCreated | Date that the file was created. |
DateLastAccessed | Date of the last time a user accessed the file. |
DateLastModified | Date of the last time a user modified the file. |
Drive | Drive letter and trailing colon (for example, C:) representing the drive on which the file is stored. |
Name | File name, not including path information. For example, the Name of the file C:\Windows\System32\Scrrun.dll is Scrrun.dll. |
ParentFolder | Name of the folder in which the file is stored. For example, the ParentFolder of C:\Windows\System32\Scrrun.dll is Windows. |
Path | Full path of the file (for example, C:\Windows\System32\Scrrun.dll). |
ShortName | |
ShortPath | |
Size | Total size, in bytes, of the contents of the file. |
Type | String describing the file type, as recorded in the registry (for example, "Microsoft Word Document"). |
To access file properties, a script must:
For example, the script in Listing 4.27 uses the GetFile method to bind to the file C:\Windows\System32\Scrrun.dll and then echoes a number of the file properties.
Listing 4.27 Enumerating File Properties
|
|
When this script runs under CScript, output similar to the following appears in the command window:
Date created: 10/29/2001 10:35:36 AM Date last accessed: 2/14/2002 1:55:44 PM Date last modified: 8/23/2001 4:00:00 AM Drive: c: Name: scrrun.dll Parent folder: C:\Windows\system32 Path: C:\Windows\system32\scrrun.dll Short name: scrrun.dll Short path: C:\Windows\system32\scrrun.dll Size: 147483 Type: Application Extension
Send us your feedback | « Previous | Next » |