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

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?  
jvpohlAsked:
Who is Participating?
 
MilanKMConnect With a Mentor Commented:
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
 
MilanKMCommented:
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
 
MilanKMCommented:
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
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.

 
MilanKMCommented:
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
 
jvpohlAuthor Commented:
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
 
MilanKMCommented:
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
 
jvpohlAuthor Commented:
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
 
jvpohlAuthor Commented:
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
 
MilanKMCommented:
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
 
MilanKMCommented:
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
 
jvpohlAuthor Commented:
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
 
TRAININGBSCCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.