Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capturing File Header Information 2

Status
Not open for further replies.
Aug 24, 2004
98
US
I need to capture file header information from any type of file on a given folder such as file type (independent from the file extension etc). Could anyone give an idea how to accomplish this with Vbscript of VB?

Thank you
 
Is this what you need?

Code:
Option Explicit
Dim oFSO: Set oFSO = CreateObject("Scripting.FileSystemObject")

GetFileInfo ("C:\")
Set oFSO = Nothing

Sub GetFileInfo (ByVal strPath)
	Dim oFolder, oSubFolders, oSubFolder, oFiles, oFile
	Set oFolder = oFSO.GetFolder (strPath)
	Set oFiles = oFolder.Files
	For Each ofile In oFiles
		WScript.Echo "FileName: " & oFile.Name
		WScript.Echo "Path: " & oFile.Path
		WScript.Echo "Attributes: " & oFile.Attributes
		WScript.Echo "Date Created: " & oFile.DateCreated
		WScript.Echo "Date Last Accessed: " & oFile.DateLastAccessed
		WScript.Echo "Date Last Modified: " & oFile.DateLastModified
		WScript.Echo "FileSize: " & oFile.Size
		WScript.Echo "FileType: " & oFile.Type & vbcrlf
	Next
	
	Set oSubFolders = oFolder.SubFolders
	For Each oSubFolder In oSubFolders
 		GetFileInfo (oSubFolder.Path)
	Next
	Set oSubFolder = Nothing
	Set oSubFolders = Nothing
	Set oFile = Nothing
	Set oFiles = Nothing
	Set oFolder = Nothing
End Sub

Please tell me if I'm wrong I like to learn from my mistakes...
_____________________________________
Feed a man a fish and feed him for a day.
Teach a man to fish and feed him for a lifetime...
 
on top of what has already been posted wmi offers some more info

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_Datafile Where name = 'c:\\Scripts\\Adsi.vbs'")
For Each objFile in colFiles
Wscript.Echo "Access mask: " & objFile.AccessMask
Wscript.Echo "Archive: " & objFile.Archive
Wscript.Echo "Compressed: " & objFile.Compressed
Wscript.Echo "Compression method: " & objFile.CompressionMethod
Wscript.Echo "Creation date: " & objFile.CreationDate
Wscript.Echo "Computer system name: " & objFile.CSName
Wscript.Echo "Drive: " & objFile.Drive
Wscript.Echo "8.3 file name: " & objFile.EightDotThreeFileName
Wscript.Echo "Encrypted: " & objFile.Encrypted
Wscript.Echo "Encryption method: " & objFile.EncryptionMethod
Wscript.Echo "Extension: " & objFile.Extension
Wscript.Echo "File name: " & objFile.FileName
Wscript.Echo "File size: " & objFile.FileSize
Wscript.Echo "File type: " & objFile.FileType
Wscript.Echo "File system name: " & objFile.FSName
Wscript.Echo "Hidden: " & objFile.Hidden
Wscript.Echo "Last accessed: " & objFile.LastAccessed
Wscript.Echo "Last modified: " & objFile.LastModified
Wscript.Echo "Manufacturer: " & objFile.Manufacturer
Wscript.Echo "Name: " & objFile.Name
Wscript.Echo "Path: " & objFile.Path
Wscript.Echo "Readable: " & objFile.Readable
Wscript.Echo "System: " & objFile.System
Wscript.Echo "Version: " & objFile.Version
Wscript.Echo "Writeable: " & objFile.Writeable
Next

'or this method?

Dim arrHeaders(34)
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("C:\Scripts")
For i = 0 to 33
arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i)
Next
For Each strFileName in objFolder.Items
For i = 0 to 33
Wscript.echo i & vbtab & arrHeaders(i) _
& ": " & objFolder.GetDetailsOf(strFileName, i)
Next
Next
 
> file header information from any type of file
When one say header info, one should have some type of files in mind, should it not? What would be the header info of a plain text file???
What would be the type of files you have in mind? Or do you think there is a universal header section of all files? If so, how long do you know it be in term of byte?

Maybe we can start there after you clarify what you know of how long it would be.
 
Thank you for the information,

I am going to actually try it. I have literally hundreed of thousands of Excel, Word, PDF, and other files. The main problem is that all of them have a .tmp file extension and I would like to write a routine that will be able to scan the folders where the data is and recognize what kind of file they are and assign the file extension that correspond to the files. I though that the file header information could be useful in order to match the data with the right extension since I can save the data from the header in a table and then depending on that data rename the files.

Thank you for all your help
 
Hi,


I am trying this version of the code on an XP machine and I am getting an "Automation Error". It fails at the point where I assign the values to the colfiles (Set colfile) What is wrong?

strComputer = "."
Set objwmiservice = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colfiles = objwmiservice.ExecQuery _
("Select * from CIM_Datafile Where path = 'c:\\SDP_TEST\Hector_Development\STEVEN\\'")
For Each objFile In colfiles
wscript.Echo "Access mask: " & objFile.AccessMask
wscript.Echo "Archive: " & objFile.Archive
wscript.Echo "Compressed: " & objFile.Compressed
wscript.Echo "Compression method: " & objFile.CompressionMethod
wscript.Echo "Creation date: " & objFile.CreationDate
wscript.Echo "Computer system name: " & objFile.CSName
wscript.Echo "Drive: " & objFile.drive
wscript.Echo "8.3 file name: " & objFile.EightDotThreeFileName
wscript.Echo "Encrypted: " & objFile.Encrypted
wscript.Echo "Encryption method: " & objFile.EncryptionMethod
wscript.Echo "Extension: " & objFile.Extension
wscript.Echo "File name: " & objFile.FileName
wscript.Echo "File size: " & objFile.filesize
wscript.Echo "File type: " & objFile.FileType
wscript.Echo "File system name: " & objFile.FSName
wscript.Echo "Hidden: " & objFile.Hidden
wscript.Echo "Last accessed: " & objFile.LastAccessed
wscript.Echo "Last modified: " & objFile.LastModified
wscript.Echo "Manufacturer: " & objFile.Manufacturer
wscript.Echo "Name: " & objFile.Name
wscript.Echo "Path: " & objFile.path
wscript.Echo "Readable: " & objFile.Readable
wscript.Echo "System: " & objFile.System
wscript.Echo "Version: " & objFile.Version
wscript.Echo "Writeable: " & objFile.Writeable
Next
 
You may replace this:
= 'c:\\SDP_TEST\Hector_Development\STEVEN\\'
By this:
Like 'c:\\SDP_TEST\\Hector_Development\\STEVEN\\%'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thank you


But the problem is that I want to process specific folders. I run with this like command it takes for ever. Any idea?

Thank you
 
>("Select * from CIM_Datafile Where path = 'c:\\SDP_TEST\Hector_Development\STEVEN\\'")
[tt]
("Select * from CIM_Datafile Where drive='c:' and path = '\\SDP_TEST\\Hector_Development\\STEVEN\\'")
[/tt]
- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top