Recipe 8.5. Viewing the Properties of a File or Folder


Problem

You 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.

Solution

Using a graphical user interface

  1. Open Windows Explorer.

  2. In the left pane, browse to the parent folder of the file or folder you want to view properties for. Click on the parent folder. This displays the list of subfolders and files in the right pane.

  3. In the right pane, right-click on the file or folder you want to view and select Properties.

  4. Several properties are displayed in the General tab. Click the Advanced button to see additional attributes.

Using a command-line interface

The 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

Discussion

Another 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 output


See Also

MS KB 320050, "HOW TO: Use the File Attribute Management Script (Fileattributes.pl) in Windows 2000"



Windows XP Cookbook
Windows XP Cookbook (Cookbooks)
ISBN: 0596007256
EAN: 2147483647
Year: 2006
Pages: 408

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net