Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
Folder date properties CreationDate, LastAccessed, and LastModified are very useful in managing folders. For example, you might use the CreationDate property to return a list of all the folders created in the past week. O,r you might use the LastAccessed property to identify rarely used folders, folders that might be candidates for compression or for removal from the file system.
The primary complication in working with folder dates is the fact that WMI stores date and time information using the UTC (Universal Time Coordinate) format. In this format, dates are displayed as yyyymmddHHMMSS.xxxxxx UUU, where:
For example, in UTC format, a folder created on October 18, 2002, at 10:45:39 A.M. Pacific Standard Time returns this CreationDate value:
20021018104539.000000 480
This means that you cannot specify a standard date, such as 10/18/2002, in your search query; WMI will not be able to interpret this date. Instead, you will need to convert any dates used in your queries to UTC format. Your converted date should use the items in Table 11.4 in each character position in the 25-character UTC string.
Table 11.4 Converting a Date to UTC Format
Character Positions | Description | Sample Value |
---|---|---|
1 4 | Four digits representing the year (such as 2001 or 2002). | 2002 |
5 6 | Two digits representing the month. For example, January is represented by the digits 01; November by the digits 11. | 10 |
7 8 | Two digits representing the day of the month. For example, the 5th day is represented by the digits 05; the 23rd day by the digits 23. | 18 |
9 14 | Six zeros representing the hours, minutes, and seconds of the day (in 24-hour format). If you prefer, you can specify values other than zero to create more finely-targeted searches. For example, to search for folders created after 1:47 P.M. on a given day, set these characters to 134700, where 13 represents the hours (1:00 P.M. in 24-hour format), 47 represents the minutes, and 00 represents the seconds. | 000000 |
15 | A period (.). | . |
16 21 | Six zeros representing the milliseconds. | 000000 |
22 25 | The number of minutes difference between your local time and Greenwich mean time. | 480 |
You can determine the offset from Greenwich mean time by using this script:
strComputer =
".
"Set objWMIService = GetObject(
"winmgmts:
"_ &
"{impersonationLevel=impersonate}!\\
"& strComputer &
"\root\cimv2
") Set colTimeZone = objWMIService.ExecQuery _ (
"SELECT * FROM Win32_TimeZone
") For Each objTimeZone in colTimeZone Wscript.Echo
"Offset:
"& objTimeZone.Bias Next
To search for folders using the date October 18, 2002, you would use a value similar to this (depending on your time zone):
20021018000000.000000 480
Listing 11.5 contains a script that returns a list of all the folders on a computer that have been created since March 1, 2002. To carry out this task, the script must perform the following steps:
To limit data retrieval to a specified set of folders, a Where clause is included restricting the returned folders to those with a CreationDate later than the target date of March 1, 2002.
Listing 11.5 Enumerating Folders Using Dates
|
|
Send us your feedback | « Previous | Next » |