TwilitGeek
-
Total Posts
:
5
- Scores: 0
-
Reward points
:
0
- Joined: 11/29/2011
-
Status: offline
|
Output Text With File Name, Product Version, and Date Modified For Files In All Subfolders
Tuesday, November 29, 2011 8:55 AM
( permalink)
Hello! :) I have two scripts that I've found on the internet and edited slightly to ALMOST do what I need.. The problem is I need both of these scripts merged into one. But my lack of knowhow and understanding in the VBScript world is hindering my success in doing so. Here's the first Script, it searches recursively and outputs most of the information I need: Set ObjFSO = CreateObject("Scripting.FileSystemObject") objStartFolder = "START FOLDER LOCATION HERE" Set objFolder = objFSO.GetFolder(objStartFolder) Set colFiles = objFolder.Files strPath = "OUTPUT TEXT FILE LOCATION HERE" Set strFile = objFSO.CreateTextFile(strPath, True) strFile.WriteLine("Name" & vbTab & "Version" & vbTab & "Date Modified") ShowSubfolders objFSO.GetFolder(objStartFolder) Sub ShowSubFolders(Folder) For Each Subfolder in Folder.SubFolders Set objFolder = objFSO.GetFolder(Subfolder.Path) Set colFiles = objFolder.Files For Each objFile in colFiles If ObjFSO.GetExtensionName(objFile) = "MSI" then strFile.WriteLine(objFile.Name & vbTab & ObjFSO.GetFileVersion(objFile) & vbTab & objFile.DateLastModified) End if If ObjFSO.GetExtensionName(objFile) = "EXE" then strFile.WriteLine(objFile.Name & vbTab & ObjFSO.GetFileVersion(objFile) & vbTab & objFile.DateLastModified) End if If ObjFSO.GetExtensionName(objFile) = "msi" then strFile.WriteLine(objFile.Name & vbTab & ObjFSO.GetFileVersion(objFile) & vbTab & objFile.DateLastModified) End if If ObjFSO.GetExtensionName(objFile) = "exe" then strFile.WriteLine(objFile.Name & vbTab & ObjFSO.GetFileVersion(objFile) & vbTab & objFile.DateLastModified) End if Next ShowSubFolders Subfolder Next End Sub Now, I don't neccisarily need it to filter out everything but MSI, msi, EXE and exe. That's just preffered. The output looks exactly how I need it, but the issue is that the "File Version" is not what I need, I need the "Product Version", and unfortunatly there's no premade command to pull that, so I have this Script: Option Explicit Dim fso, fc, f, fs Dim strPath, strFile 'On Error Resume Next strPath = "OUTPUT TEXT FILE LOCATION HERE" Set fso = CreateObject("Scripting.FileSystemObject") Set strFile = fso.CreateTextFile(strPath, True) strFile.WriteLine("Name" & vbTab & "Version" & vbTab & "Date Modified") Set f = fso.GetFolder("FOLDER LOCATION HERE") Set fc = f.Files For Each fs In fc strFile.WriteLine(fs.Name & vbTab & GetProductVersion ("FOLDER LOCATION HERE", fs.Name) & vbTab & fs.DateLastModified) Next Function GetProductVersion (sFilePath, sProgram) Dim objShell, objFolder, objFolderItem, i If FSO.FileExists(sFilePath & "\" & sProgram) Then Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.Namespace(sFilePath) Set objFolderItem = objFolder.ParseName(sProgram) Dim arrHeaders(300) For i = 0 To 300 arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i) 'WScript.Echo i &"- " & arrHeaders(i) & ": " & objFolder.GetDetailsOf(objFolderItem, i) If lcase(arrHeaders(i))= "product version" Then GetProductVersion= objFolder.GetDetailsOf(objFolderItem, i) Exit For End If Next End If End Function Now if you haven't already noticed, the problem with this script is that although it outputs exactly what I need, it only does it for a single folder. But I need it for a folder and all subfolders under it. I'm sure there must be some way to stuff this function into my previous script, but I can't figure it out. Haha~ If anyone could mend these scripts or give me some tips on how I can make them work the way I need it'd be much appreciated! Thanks in advance. :D
<message edited by TwilitGeek on Tuesday, November 29, 2011 11:17 AM>
|
|
|
|
Hackoo
-
Total Posts
:
105
- Scores: 4
-
Reward points
:
0
- Joined: 6/25/2010
-
Status: offline
|
Re:Search for File Name, Product Version, and Date Last Modified
Tuesday, November 29, 2011 10:54 AM
( permalink)
Hi ! I made a Vbscript like this and you can try it at this link It is a Vbscript to search for files by their extensions and organize them by copying in different folders with names on their extensions chosen from the beginning of the research, and generate search results in a table in HTML, citing information on these files such that their paths, creation date, modification date, size and attributes;and display thumbnails of diffrent types of images in the search, Eg if the search includes image files will be displayed as thumbnails.
|
|
|
|
TwilitGeek
-
Total Posts
:
5
- Scores: 0
-
Reward points
:
0
- Joined: 11/29/2011
-
Status: offline
|
Re:Search for File Name, Product Version, and Date Last Modified
Tuesday, November 29, 2011 11:19 AM
( permalink)
Thanks! But that's a lot more complicated than what I need. The first script that I posted actually does what I need, mostly, but it needs the addition from the second script to give me the Product Version of files, instead of the File Versions. I just can't figure out how to get them merged together without resulting in just errors. :(
|
|
|
|
59cobalt
-
Total Posts
:
979
- Scores: 91
-
Reward points
:
0
- Joined: 7/17/2011
-
Status: offline
|
Re:Output Text With File Name, Product Version, and Date Modified For Files In All Subfold
Tuesday, November 29, 2011 11:33 AM
( permalink)
Check the FAQ for folder recursion.
|
|
|
|
TwilitGeek
-
Total Posts
:
5
- Scores: 0
-
Reward points
:
0
- Joined: 11/29/2011
-
Status: offline
|
Re:Output Text With File Name, Product Version, and Date Modified For Files In All Subfold
Tuesday, November 29, 2011 11:57 AM
( permalink)
Thanks! Just took a look at that, I already know how to go through folders recursively, what I don't know how to do is get the function that grabs the "Product Version" into the recursion. For instance.. I would personally assume it should look like this: Set ObjFSO = CreateObject("Scripting.FileSystemObject") objStartFolder = "START FOLDER LOCATION" Set objFolder = objFSO.GetFolder(objStartFolder) Set colFiles = objFolder.Files strPath = "OUTPUT TEXT FILE LOCATION" Set strFile = objFSO.CreateTextFile(strPath, True) strFile.WriteLine("Name" & vbTab & "Version" & vbTab & "Date Modified") ShowSubfolders objFSO.GetFolder(objStartFolder) Sub ShowSubFolders(Folder) For Each Subfolder in Folder.SubFolders Set objFolder = objFSO.GetFolder(Subfolder.Path) Set colFiles = objFolder.Files For Each objFile in colFiles strFile.WriteLine(objFile.Name & vbTab & GetProductVersion & vbTab & objFile.DateLastModified) Next ShowSubFolders Subfolder Next End Sub Function GetProductVersion (sFilePath, sProgram) Dim objShell, objFolder, objFolderItem, i If FSO.FileExists(sFilePath & "\" & sProgram) Then Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.Namespace(sFilePath) Set objFolderItem = objFolder.ParseName(sProgram) Dim arrHeaders(300) For i = 0 To 300 arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i) 'WScript.Echo i &"- " & arrHeaders(i) & ": " & objFolder.GetDetailsOf(objFolderItem, i) If lcase(arrHeaders(i))= "product version" Then GetProductVersion= objFolder.GetDetailsOf(objFolderItem, i) Exit For End If Next End If End Function But this doesn't work, it just gives an error saying that "GetProductVersion" on this line: "strFile.WriteLine(objFile.Name & vbTab & GetProductVersion & vbTab & objFile.DateLastModified)" has "Wrong number of arguments or invalid property assignment" So, I'm not sure on the proper verbage for this, but basically I need the script to call the GetProductVersion function inside the recursion that's already inplace, to grab and output the product version of each file.
|
|
|
|
59cobalt
-
Total Posts
:
979
- Scores: 91
-
Reward points
:
0
- Joined: 7/17/2011
-
Status: offline
|
Re:Output Text With File Name, Product Version, and Date Modified For Files In All Subfold
Tuesday, November 29, 2011 12:16 PM
( permalink)
TwilitGeek But this doesn't work, it just gives an error saying that "GetProductVersion" on this line: "strFile.WriteLine(objFile.Name & vbTab & GetProductVersion & vbTab & objFile.DateLastModified)" has "Wrong number of arguments or invalid property assignment" So, I'm not sure on the proper verbage for this, but basically I need the script to call the GetProductVersion function inside the recursion that's already inplace, to grab and output the product version of each file. Well, apparently the function is defined with two arguments: Function GetProductVersion (sFilePath, sProgram) but called with none: strFile.WriteLine(objFile.Name & vbTab & GetProductVersion & vbTab & objFile.DateLastModified) The proper course of action to fix this issue should be obvious.
|
|
|
|
TwilitGeek
-
Total Posts
:
5
- Scores: 0
-
Reward points
:
0
- Joined: 11/29/2011
-
Status: offline
|
Re:Output Text With File Name, Product Version, and Date Modified For Files In All Subfold
Tuesday, November 29, 2011 12:57 PM
( permalink)
Ahhhhhhh, alright, that much makes sense. So my correction is as follows: Set ObjFSO = CreateObject("Scripting.FileSystemObject") objStartFolder = "START FOLDER LOCATION" Set objFolder = objFSO.GetFolder(objStartFolder) Set colFiles = objFolder.Files strPath = "OUTPUT TEXT LOCATION" Set strFile = objFSO.CreateTextFile(strPath, True) strFile.WriteLine("Name" & vbTab & "Version" & vbTab & "Date Modified") ShowSubfolders objFSO.GetFolder(objStartFolder) Sub ShowSubFolders(Folder) For Each Subfolder in Folder.SubFolders Set objFolder = objFSO.GetFolder(Subfolder.Path) Set colFiles = objFolder.Files For Each objFile in colFiles strFile.WriteLine(objFile.Name & vbTab & GetProductVersion (Subfolder.Path, objFile.Name) & vbTab & objFile.DateLastModified) Next ShowSubFolders Subfolder Next End Sub Function GetProductVersion (sFilePath, sProgram) Dim objShell, objFolders, objFolderItem, i If objFSO.FileExists(sFilePath & "\" & sProgram) Then Set objShell = CreateObject("Shell.Application") Set objFolders = objShell.Namespace(sFilePath) Set objFolderItem = objFolders.ParseName(sProgram) Dim arrHeaders(300) For i = 0 To 300 arrHeaders(i) = objFolders.GetDetailsOf(objFolders.Items, i) 'WScript.Echo i &"- " & arrHeaders(i) & ": " & objFolders.GetDetailsOf(objFolderItem, i) If lcase(arrHeaders(i))= "product version" Then GetProductVersion= objFolders.GetDetailsOf(objFolderItem, i) Exit For End If Next End If End Function WHICH WORKS! YAAAY~ I'm so happy now. Thanks a TON! I've seriously been trying different scripts and such off and on for weeks to get this task accomplished, really appreciate it! :) I still only understand maybe 75% of the things that even happen in this script, I definatly have a lot to learn! But at least this one works now. Thanks again!
<message edited by TwilitGeek on Tuesday, November 29, 2011 1:06 PM>
|
|
|
|
59cobalt
-
Total Posts
:
979
- Scores: 91
-
Reward points
:
0
- Joined: 7/17/2011
-
Status: offline
|
Re:Output Text With File Name, Product Version, and Date Modified For Files In All Subfold
Wednesday, November 30, 2011 6:04 AM
( permalink)
|
|
|
|