ProblemYou want to view the creation or last modification timestamp of a file or folder or determine whether it is encrypted, archived, compressed, and so on. SolutionUsing a graphical user interface
Using a command-line interfaceThe dir command can be run as part of a CMD session to display the last-modified time, size, and owner of a file or directory. Here is an example: > dir /q <Path> You can also display other attributes of a file or folder with the /A option. Run dir /? for a complete list of options and parameters. One way to view the files on a remote system is to use a UNC path. This command displays the contents of the c:\scripts folder on the host fs01: > dir /q \\fs01\c$\scripts You can use the runas command to specify alternate credentials if needed or use the Sysinternals psexec command. Using VBScript' This code displays the properties and attributes of a file ' ------ SCRIPT CONFIGURATION ------ strFilePath = "d:\\myfile.txt" strComputer = "." ' ------ END CONFIGURATION --------- set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set objFile = objWMI.Get("CIM_Datafile=""" & strFilePath & """") WScript.Echo objFile.Name WScript.Echo " 8.3 Name: " & objFile.EightDotThreeFileName WScript.Echo " Drive: " & objFile.Drive WScript.Echo " FileName: " & objFile.FileName WScript.Echo " Extension: " & objFile.Extension WScript.Echo " FileType: " & objFile.FileType WScript.Echo " Path: " & objFile.Path WScript.Echo " InUse Counter: " & objFile.InUseCount WScript.Echo " Creation Date: " & objFile.CreationDate WScript.Echo " Last Accessed: " & objFile.LastAccessed WScript.Echo " Last Modified: " & objFile.LastModified WScript.Echo " Archive: " & objFile.Archive WScript.Echo " Compressed: " & objFile.Compressed WScript.Echo " Encrypted: " & objFile.Encrypted WScript.Echo " System: " & objFile.System WScript.Echo " Writeable: " & objFile.Writeable WScript.Echo " Hidden: " & objFile.Hidden ' This code displays the properties and attributes of a folder ' ------ SCRIPT CONFIGURATION ------ strDirPath = "c:\\scripts" strComputer = "." ' ------ END CONFIGURATION --------- set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set objFile = objWMI.Get("Win32_Directory=""" & strDirPath & """") WScript.Echo objFile.Name WScript.Echo " 8.3 Name: " & objFile.EightDotThreeFileName WScript.Echo " Drive: " & objFile.Drive WScript.Echo " Folder Name: " & objFile.FileName WScript.Echo " File Type: " & objFile.FileType WScript.Echo " Path: " & objFile.Path WScript.Echo " InUse Counter: " & objFile.InUseCount WScript.Echo " Creation Date: " & objFile.CreationDate WScript.Echo " Last Accessed: " & objFile.LastAccessed WScript.Echo " Last Modified: " & objFile.LastModified WScript.Echo " Archive: " & objFile.Archive WScript.Echo " Compressed: " & objFile.Compressed WScript.Echo " Encrypted: " & objFile.Encrypted WScript.Echo " System: " & objFile.System WScript.Echo " Writeable: " & objFile.Writeable WScript.Echo " Hidden: " & objFile.Hidden DiscussionAnother useful tool for displaying file information is Visual File Information (vfi.exe) from the Resource Kit. It can display file information for several files on a single screen. You start by selecting a folder and from there it enumerates every file contained within that folder and all subfolders. You can then sort by creation or modification date, size, extension, and a number of other attributes. The tool is good at enumerating over hundreds or even thousands of files very quickly, so if you wanted to find the largest file on a disk or find the most recently modified file, this would be a great tool for the job. Figure 8-1 shows sample output from VFI. Figure 8-1. Visual File Information sample outputSee AlsoMS KB 320050, "HOW TO: Use the File Attribute Management Script (Fileattributes.pl) in Windows 2000" |