[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

OutPut the following: File Name, File Size, File Date, and File Version

Posted on 2006-05-21
12
Medium Priority
?
3,430 Views
Last Modified: 2013-11-12
I am new to VBS and am looking how to create a VBS script to extract the FILE NAME, FILE SIZE, FILE SIZE and FILE VERSION to a text file.  I can do everything with piping dir c:\windows\*.* /s >c:\windows.txt but I am not able to get the Version information in the file.  

I understand that not all files with will have version information and that is ok....if no version information is provided maybe have it stat that in the text file as well.

Any ideas on how to do this in VBS?  
0
Comment
Question by:jvpohl
  • 7
  • 4
12 Comments
 
LVL 14

Expert Comment

by:MilanKM
ID: 16727999
Cheers! Here's the VBS code that you're looking for,

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("c:\myFile.txt")

Wscript.Echo "Date created: " & objFile.DateCreated
Wscript.Echo "Date last accessed: " & objFile.DateLastAccessed
Wscript.Echo "Date last modified: " & objFile.DateLastModified
Wscript.Echo "Drive: " & objFile.Drive
Wscript.Echo "Name: " & objFile.Name
Wscript.Echo "Parent folder: " & objFile.ParentFolder
Wscript.Echo "Path: " & objFile.Path
Wscript.Echo "Short name: " & objFile.ShortName
Wscript.Echo "Short path: " & objFile.ShortPath
Wscript.Echo "Size: " & objFile.Size
Wscript.Echo "Type: " & objFile.Type

Just replace "myfile.txt" here
Set objFile = objFSO.GetFile("c:\myFile.txt")

Thanks
MilanKM
0
 
LVL 14

Expert Comment

by:MilanKM
ID: 16728007
For version try following
Wscript.Echo "Version: " & objFile.Version
but it'll not work for file types like txt, doc. May work for system files like dll, ocx.
0
 
LVL 14

Expert Comment

by:MilanKM
ID: 16728012
also try this

Set objFSO = CreateObject("Scripting.FileSystemObject")
Wscript.Echo objFSO.GetFileVersion("c:\windows\system32\msvbvm60.dll")

It works fine, just replace the file address you want.

Thanks
MilanKM
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:jvpohl
ID: 16729680
First I wanted to thank you for such a quick response!!!!  The 1st example did not work no output to the myfile.txt.  But I think it will, I just don’t know enough about VBS yet to make it work.  So I think we are close!!


So to clear up what I am trying to do, is the following….I would basically need the following:  To execute a vbs script that will search several folders and output the results to a text file with no user intervention.  This will be an event that runs every night on the computer.   Below is an example of what I would be looking for …

Again thank you…

    Name   5                                        Size   Type                    Date Modified           File Version            Product Version
    uedit32.mnu                                 22 KB   MNU File                4/4/2006 4:36 AM
    uedit32.pmu                                  7 KB   PMU File                4/4/2006 4:36 AM
    uedit32.tbr                                  2 KB   TBR File                4/4/2006 4:36 AM
    uninst.exe                                 292 KB   Application             11/5/1996 5:13 PM       2.20.920.0              2.20.920.0
    UNNeroBackItUp.cfg                           1 KB   Microsoft Office Ou...  8/30/2005 9:33 PM
    UNNeroBackItUp.exe                         228 KB   Application             9/12/2005 4:13 PM       1.0.0.4                 1,0,0,4
    UNNeroMediaHome.cfg                          1 KB   Microsoft Office Ou...  9/15/2005 2:35 PM
    UNNeroMediaHome.exe                        228 KB   Application             9/12/2005 4:13 PM       1.0.0.4                 1,0,0,4
    UNNeroShowTime.cfg                           1 KB   Microsoft Office Ou...  8/30/2005 9:37 PM
    UNNeroShowTime.exe                         228 KB   Application             9/12/2005 4:13 PM       1.0.0.4                 1,0,0,4
    UNNeroVision.cfg                             1 KB   Microsoft Office Ou...  8/30/2005 9:37 PM
    UNNeroVision.exe                           228 KB   Application             9/12/2005 4:13 PM       1.0.0.4                 1,0,0,4
    UNRecode.cfg                                 1 KB   Microsoft Office Ou...  8/30/2005 9:36 PM
    UNRecode.exe                               228 KB   Application             9/12/2005 4:13 PM       1.0.0.4                 1,0,0,4
    updspapi.log                                37 KB   Text Document           5/10/2006 3:00 AM
    vb.ini                                       1 KB   Configuration Settings  3/18/2006 9:35 PM
    vbaddin.ini                                  1 KB   Configuration Settings  3/18/2006 9:35 PM
    vmmreg32.dll                                19 KB   Application Extension   8/4/2004 7:00 AM        5.1.2600.0              5.1.2600.0
0
 
LVL 14

Expert Comment

by:MilanKM
ID: 16729817
Hi,

the above code on my previous comments will produce info of a perticular file. I skipped that you need the out put in a text file. So sorry about that. As I get time I will try to produce that.

Thanks
MilanKM
0
 
LVL 14

Accepted Solution

by:
MilanKM earned 2000 total points
ID: 16729996
Hi,

Atlast it is done. Here just change the folder name & the logFile name as u need. I've done the example with Name, Size & Type. If u need more then just append. I think u can understand the code.

Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\Log.txt")
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("c:\MyFolder")
Set colListOfFiles = objFolder.Files
Set objTextFile = objFSO.OpenTextFile("c:\log.txt", ForAppending, True)
objTextFile.WriteLine("NAME    SIZE    TYPE")
objTextFile.Close

For Each objFile in colListOfFiles
  Set objTextFile = objFSO.OpenTextFile ("C:\Log.txt", ForAppending, True)
  objTextFile.WriteLine(objFile.Name&"    "&objFile.Size&"    "&objFile.Type&"    ")
  objTextFile.Close
Next
0
 

Author Comment

by:jvpohl
ID: 16730815
Almost Perfect!  Before I wrote this I believe I have exhausted all resources as I am trying to learn VBS with your help on this project.

This is the script as it is now….

Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("c:\Log.txt")
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("c:\windows")
Set colListOfFiles = objFolder.Files
Set objTextFile = objFSO.OpenTextFile("c:\log.txt", ForAppending, True)
objTextFile.WriteLine("NAME|    SIZE|    TYPE|    DATE LAST MMODIFIED|    FILE VERSION")
objTextFile.Close

For Each objFile in colListOfFiles
  Set objTextFile = objFSO.OpenTextFile ("j:\Log.txt", ForAppending, True)
  objTextFile.WriteLine(objFile.Name&"|    "&objFile.Size&"|    "&objFile.Type&"|    "&objFile.DateLastModified&"|    "&objFile.ProductVersion&"   ")
  objTextFile.Close
Next

It does work as long as you do not use the "&objFile.ProductVersion&" I also tried the "&objFile.Version&" but I get the following error:

Windows Script Host
             Script:  c:\version.vbs
             Line:    14
             Char:    3
             Error:   Object doesn't support this property or method: 'objFile.Version'
             Code:    800A01B6
             Source:  Microsoft VBScript runtime error
                                         
I researched the method and Version does not appear as a valid method unless you use objFSO.GetFileVersion.  

What are your thoughts on this?  Do we need to go another way?  (also as you can see I put the pipe symbol in as a delimiter to make it easier to import into excel or whatever)
0
 

Author Comment

by:jvpohl
ID: 16731214
After a few more hours of working on this....I found what I was doing wrong....All I needed to do was the following...

  objTextFile.WriteLine(objFile.Name&"|    "&objFile.Size&"|    "&objFile.Type&"|    "&objFile.DateLastModified&"|   ")& objFSO.GetFileVersion(objFile)


MilanKM thank you very much for pointing me in the correct direction!

0
 
LVL 14

Expert Comment

by:MilanKM
ID: 16731715
Hi jvpohl,

Glad to help u. On my last code I just put Name, Type & Size. And I also wrote to add other properties u want. Anyways thanks.

MilanKM
0
 
LVL 14

Expert Comment

by:MilanKM
ID: 16731727
Oh! one more thing when I was writing that code it was too late night. About 2.00 AM & that why I give u the main code but could not done the formatting.
0
 

Author Comment

by:jvpohl
ID: 16739465
MilanKM - Thank you....I learned alot with your help! I would not have learned anything if you just did it all for me.... :)

Again, thank you!

JP
0
 

Expert Comment

by:TRAININGBSC
ID: 29082435
Hi guys,

I added a new object on a new column called Date Last Accessed" as you can see  objTextFile.WriteLine(objFile.Name&"|    "&objFile.Size&"|    "&objFile.Type&"|    "&objFile.DateLastModified&"|   "&objFile.DateLastAccessed&"|   ")& objFSO.GetFileVersion(objFile)

But everytime that I ran the script is giving to me the data that I run the report no the REAL Date Last Accessed.

many thanks !!!!!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question