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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with getting file size and last modified date

Status
Not open for further replies.

thutmose

MIS
Mar 31, 2002
24
US
I am a newbie to scripting so it took me a while to get this to working. I have this vbscript below which finds certain files of a certain filetype. No matter what drive is mapped I can print out a file and its location. I was trying to also get the last modified date and size. I was looking at getfilesize but having problems incorporating this into my script. Any help would be appreciated, thanks.


strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_DataFile Where Extension = 'doc'")
If colFiles.Count = 0 Then
Wscript.Quit
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile("C:\Scripts\PST_Data.txt")
For Each objFile in colFiles
objTextFile.Write(objFile.Drive & objFile.Path & ",")
objTextFile.Write(objFile.FileName & "." & objFile.Extension & ",")
objTextFile.Write(objFile.FileSize & vbCrLf)
Next
objTextFile.Close
 
[1] >I was looking at getfilesize but having problems incorporating this into my script.
You have already this line.
[tt] objTextFile.Write(objFile.FileSize & vbCrLf)[/tt]
That is the file size in byte. So I suppose that is not a problem?

[2] >I was trying to also get the last modified date...
This is slightly more involved. The property LastModified result in cim_datetime format. An interpretation can be found here:
with example of how to parse it yourself.

[2.1] You can use swbemdatetime object to do the conversion automatically for you (with other useful format). Here is how you do.

[2.1.1] Add an initiatiation of a swbemdatetime object at the top of the script.
[tt]
Set swbemdt = CreateObject("WbemScripting.SWbemDateTime")
[/tt]
[2.1.2] Do the conversion and write it out.
[tt]
For Each objFile in colFiles
objTextFile.Write(objFile.Drive & objFile.Path & ",")
objTextFile.Write(objFile.FileName & "." & objFile.Extension & ",")
[blue]swbemdt.value=objFile.lastmodified
objTextFile.Write(swbemdt.GetVarDate & ",")[/blue]
objTextFile.Write(objFile.FileSize & vbCrLf)
Next
[/tt]
[2.2] SWbemDateTime object documentation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top