umass
Members-
Posts
17 -
Joined
-
Last visited
Reputation
0 NeutralAbout umass

-
hey, Some updates: Everything is working well now. I've used the administrative share $C along with the computer name and directory. Also, I noticed that since I'm running the script from the command prompt, if I don't run the cmd as an administrator it brings me back to the "Path not found" issue for some reason. My only issue now is Time Efficiency. The full algorithm that searches for all sorts of files is a O(n^3) complexity and of course it will take a very long time to query about 111 computers. The algorithm is that complex because of the number of loops I'm using. For that reason I wanted to ask, if I tell the script to search for a specific file type, do I have to tell it to search folders and subfolders, or would it do it automatically?
-
Ok. I've added some comments, hope it helps understanding the flow of the code. [ CODE ] Option Explicit Dim strComputer, objSWbemLocator, objFile, objOut, totalSize, FileSize Dim counter, strFolderToSearch, FileType, objFso, objFolder, SubFolder Dim strXP, str7, objSWbemServices Dim strComputerArray, FileTypeArray 'variables used for computing file size const bytesToKB = 1024 const bytesToMB = 1048576 const bytesToGB = 1073741824 Dim M, F, C, L, T, P M = "Machine" F = "File Type" C = "Count" L = "Directory" T = "Total Size" strComputer = "finaid254" 'remote computer name to be queried FileType = "MP3" 'file type to look for Set objFso = CreateObject("Scripting.FileSystemObject") Set objOut = objFso.CreateTextFile("Media2.csv", True) objOut.WriteLine M & "," & F & "," & C & "," & L & "," & T Call SearchDocs(strComputer) Function SearchDocs(ComputerName) FileSize = 0 Dim colFiles strFolderToSearch = "Users" 'remote computer directory to be queried 'Connect to remote computer Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator") Set objSWbemServices = objSWbemLocator.ConnectServer _ (ComputerName, "root\cimv2", "SARIS\faadmin", ";4y'#h4ny`") objSWbemServices.Security_.ImpersonationLevel = 3 'set folder to be queried Set colFiles = objSWbemServices.ExecQuery _ ("ASSOCIATORS OF {Win32_Directory.Name=" & _ "'" & "\\" & ComputerName & "\C$\" & strFolderToSearch & "'} Where " _ & "ResultClass = CIM_DataFile") 'Get folder with Administrative share 'C$' Set objFolder = objFso.GetFolder("\\" & ComputerName & "\C$\" & strFolderToSearch) Set colFiles = objFolder.Files counter = 0 For Each objFile In colFiles if UCase(objFso.GetExtensionName(objFile.name)) = FileType Then 'Wscript.Echo "found " & objFile.Name & " in" & Subfolder.Path & "." counter = counter + 1 'count how many files of a certain extension there are FileSize = FileSize + objFile.Size 'calculate total size of all files Wscript.Echo "found " & objFile.name & " in " & objFolder.Path & " ." End if Next 'This if-statement will just write the computername, filetype, file count, the directory 'and the total size to an output file if (counter>0) and (FileSize>0) then if (FileSize < bytesToKB) then totalSize = FileSize objOut.WriteLine ComputerName & FileType & counter _ & objFolder.Path & totalSize & " bytes" end if if (FileSize >= bytesToKB) and (FileSize < bytesToMB) then totalSize = FileSize / bytesToKB objOut.WriteLine ComputerName & FileType & counter _ & objFolder.Path & totalSize & " KB" end if if (FileSize >= bytesToMB) and (FileSize < bytesToGB) then totalSize = FileSize / bytesToMB objOut.WriteLine ComputerName & FileType & counter _ & objFolder.Path & totalSize & " MB" end if if (FileSize >= bytesToGB) then totalSize = FileSize / bytesToGB objOut.WriteLine ComputerName & FileType & counter _ & objFolder.Path & totalSize & " GB" end if end if ShowSubfolders objFso.GetFolder("\\finaid254\C$\" & strFolderToSearch) End Function 'This Sub traverses all subfolders of a primary directory, counts files, computes 'tota size per location and writes all the data to an output file Sub ShowSubFolders(Folder) Dim colFiles For Each Subfolder in Folder.SubFolders Set colFiles = objSWbemServices.ExecQuery _ ("ASSOCIATORS OF {Win32_Directory.Name=" & _ "'" & Folder & "'} Where " _ & "ResultClass = CIM_DataFile") counter = 0 FileSize = 0 Wscript.Echo Subfolder.Path Set objFolder = objFso.GetFolder(Subfolder.Path) Set colFiles = objFolder.Files For Each objFile in colFiles if UCase(objFso.GetExtensionName(objFile.name)) = FileType Then Wscript.Echo "found " & objFile.Name & " in " & Subfolder.Path & "." FileSize = FileSize + objFile.Size counter = counter + 1 End if Next if (counter>0) and (FileSize>0) then if (FileSize < bytesToKB) then totalSize = FileSize objOut.WriteLine strComputer & "," & FileType & "," & counter _ & "," & Subfolder.Path & "," & totalSize & " bytes" end if if (FileSize >= bytesToKB) and (FileSize < bytesToMB) then totalSize = FileSize / bytesToKB objOut.WriteLine strComputer & "," & FileType & "," & counter _ & "," & Subfolder.Path & "," & totalSize & " KB" end if if (FileSize >= bytesToMB) and (FileSize < bytesToGB) then totalSize = FileSize / bytesToMB objOut.WriteLine strComputer & "," & FileType & "," & counter _ & "," & Subfolder.Path & "," & totalSize & " MB" end if if (FileSize >= bytesToGB) then totalSize = FileSize / bytesToGB objOut.WriteLine strComputer & "," & FileType & "," & counter _ & "," & Subfolder.Path & "," & totalSize & " GB" end if end if ShowSubFolders Subfolder Next End Sub [ /CODE ]
-
Yeah i should definitely do that. I'll comment it and I'll re-post it. I actually have a bunch of irrelevant comments there, but I'll clean it up a little. What do you mean by code tags though? (sry im a newb here...) Thanks
-
Just an update: I found a huge mistake. I found out that I can't just use FSO to get into the folder of a remote computer.I read some documentations and found out that I have to use administrative shares such as C$, to get the folder information. I wrote a test code and it seems to be working fine up until the following line "For each objFile in colFiles" in the ShowSubFolders sub. The error was Error:0x8007013D, Code:8007013D, Source:(null). Here is the code: Option Explicit Dim strComputer, objSWbemLocator, objFile, objOut, totalSize, FileSize Dim counter, strFolderToSearch, FileType, objFso, objFolder, SubFolder Dim strXP, str7, objSWbemServices Dim strComputerArray, FileTypeArray const bytesToKB = 1024 const bytesToMB = 1048576 const bytesToGB = 1073741824 Dim M, F, C, L, T, P M = "Machine" F = "File Type" C = "Count" L = "Directory" T = "Total Size" 'will change strComputer to an array that stores all the finaid computer names 'then call SearchDocs with each strComputer array index strComputer = "compName" 'Will create an array of all kinds of picture and media files then send it as a parameter 'to searchDocs with each FileType array index FileType = "MP3" Set objFso = CreateObject("Scripting.FileSystemObject") Set objOut = objFso.CreateTextFile("Media2.csv", True) objOut.WriteLine M & "," & F & "," & C & "," & L & "," & T Call SearchDocs(strComputer) Function SearchDocs(ComputerName) FileSize = 0 Dim colFiles strFolderToSearch = "Users" Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator") Set objSWbemServices = objSWbemLocator.ConnectServer _ (ComputerName , "root\cimv2", "admin", "password") objSWbemServices.Security_.ImpersonationLevel = 3 Set colFiles = objSWbemServices.ExecQuery _ ("ASSOCIATORS OF {Win32_Directory.Name=" & _ "'" & strFolderToSearch & "'} Where " _ & "ResultClass = CIM_DataFile") Set objFolder = objFso.GetFolder("\\compName\C$\" & strFolderToSearch) Set colFiles = objFolder.Files counter = 0 For Each objFile In colFiles if UCase(objFso.GetExtensionName(objFile.name)) = FileType Then 'Wscript.Echo "found " & objFile.Name & " in" & Subfolder.Path & "." counter = counter + 1 FileSize = FileSize + objFile.Size Wscript.Echo "found " & objFile.name & " in " & objFolder.Path & " ." End if Next if (counter>0) and (FileSize>0) then if (FileSize < bytesToKB) then totalSize = FileSize objOut.WriteLine ComputerName & FileType & counter _ & objFolder.Path & totalSize & " bytes" end if if (FileSize >= bytesToKB) and (FileSize < bytesToMB) then totalSize = FileSize / bytesToKB objOut.WriteLine ComputerName & FileType & counter _ & objFolder.Path & totalSize & " KB" end if if (FileSize >= bytesToMB) and (FileSize < bytesToGB) then totalSize = FileSize / bytesToMB objOut.WriteLine ComputerName & FileType & counter _ & objFolder.Path & totalSize & " MB" end if if (FileSize >= bytesToGB) then totalSize = FileSize / bytesToGB objOut.WriteLine ComputerName & FileType & counter _ & objFolder.Path & totalSize & " GB" end if end if ShowSubfolders objFso.GetFolder("\\compName\C$\" & strFolderToSearch) End Function Sub ShowSubFolders(Folder) Dim colFiles For Each Subfolder in Folder.SubFolders Set colFiles = objSWbemServices.ExecQuery _ ("ASSOCIATORS OF {Win32_Directory.Name=" & _ "'" & Folder & "'} Where " _ & "ResultClass = CIM_DataFile") counter = 0 FileSize = 0 Wscript.Echo Subfolder.Path Set objFolder = objFso.GetFolder(Subfolder.Path) Set colFiles = objFolder.Files 'On Error Resume Next For Each objFile in colFiles REM If Err.Number Then REM continue REM End if if UCase(objFso.GetExtensionName(objFile.name)) = FileType Then Wscript.Echo "found " & objFile.Name & " in " & Subfolder.Path & "." 'totalSize = objFso.GetFile(Subfolder.Path & "\" & objFile.Name) FileSize = FileSize + objFile.Size counter = counter + 1 End if Next if (counter>0) and (FileSize>0) then if (FileSize < bytesToKB) then totalSize = FileSize objOut.WriteLine strComputer & "," & FileType & "," & counter _ & "," & Subfolder.Path & "," & totalSize & " bytes" end if if (FileSize >= bytesToKB) and (FileSize < bytesToMB) then totalSize = FileSize / bytesToKB objOut.WriteLine strComputer & "," & FileType & "," & counter _ & "," & Subfolder.Path & "," & totalSize & " KB" end if if (FileSize >= bytesToMB) and (FileSize < bytesToGB) then totalSize = FileSize / bytesToMB objOut.WriteLine strComputer & "," & FileType & "," & counter _ & "," & Subfolder.Path & "," & totalSize & " MB" end if if (FileSize >= bytesToGB) then totalSize = FileSize / bytesToGB objOut.WriteLine strComputer & "," & FileType & "," & counter _ & "," & Subfolder.Path & "," & totalSize & " GB" end if end if ShowSubFolders Subfolder Next End Sub 'wscript.quit 'Wscript.Echo "total number of " & FileType & " files found = " & counter & "."
-
Hey Synack...thanks for your response. What do you mean by "what user context are you running it in"? And how do I go about having my script take ownership, or running it as a member of the backup operators group? (I'm new to VBScript btw...so pardon my ignorance)
-
Here it is. Basically what I'm trying to do is to query every audio, video and image file in remote computers that are listed in the Active Directory (Windows Server 2008). The full code is bellow. Option Explicit Dim strComputer, objOut, totalSize Dim strFolderToSearch, objFso, objFolder, SubFolder Dim strXP, str7, colOperatingSystems, stringArray, objSWbemLocator, objSWbemServices Dim strComputerArray, FileTypeArray Dim objConnection, objCommand, objRecordSet Dim searchStr, Folder Dim FileType(36), Ftype, objOut2 Dim objPing, objStatus, stat const bytesToKB = 1024 const bytesToMB = 1048576 const bytesToGB = 1073741824 Const ADS_SCOPE_SUBTREE = 2 strXP = "XP" str7 = "7" 'FILE TYPES FOR AUDIO, VIDEO AND IMAGE FileType(0) = "WMA" FileType(1) = "MP3" FileType(2) = "AWB" FileType(3) = "FLAC" FileType(4) = "M4P" FileType(5) = "OGG" FileType(6) = "RAW" FileType(7) = "WAV" FileType(8) = "AAC" FileType(9) = "ALAC" FileType(10) = "MPC" FileType(11) = "3GP" FileType(12) = "MPEG" FileType(13) = "MPG" FileType(14) = "IFF" FileType(15) = "JPEG" FileType(16) = "JFIF" FileType(17) = "PNG" FileType(18) = "GIF" FileType(19) = "JPG" FileType(20) = "TIFF" FileType(21) = "BMP" FileType(22) = "PSD" FileType(23) = "PGF" FileType(24) = "TGA" FileType(25) = "PSP" FileType(26) = "WMV" FileType(27) = "ASF" FileType(28) = "ASX" FileType(29) = "3G2" FileType(30) = "FLV" FileType(31) = "SWF" FileType(32) = "AVI" FileType(33) = "ALAW" FileType(34) = "ULAW" FileType(35) = "MKV" Set objFso = CreateObject("Scripting.FileSystemObject") Set objOut = objFso.CreateTextFile("Media.csv", True) Set objOut2 = objFso.CreateTextFile("os.txt", True) Call GetCompName() Function GetCompName() Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" Set objCOmmand.ActiveConnection = objConnection objCommand.CommandText = _ "Select Name, Location from 'LDAP://domain' " _ & "Where objectClass='computer'" objCommand.Properties("Page Size") = 1000 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst searchStr = "str" Do Until objRecordSet.EOF if InStr(lcase(objRecordSet.Fields("Name").Value), lcase(searchStr)) = 1 then strComputer = objRecordSet.Fields("Name").Value Call Check_comp_status(strComputer) if (stat=1) then Call checkOS(strComputer) else objOut.WriteLine strComputer & " machine is offline." end if End if stat = 0 'reset stat objRecordSet.MoveNext Loop objOut.WriteLine "***End of List***" Wscript.Echo "DONE!!" wscript.quit End Function Function Check_comp_status(ComputerName) Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._ ExecQuery("select Replysize from Win32_PingStatus where address = '" & ComputerName & "'") For Each objStatus in objPing If IsNull(objStatus.ReplySize) Then stat = 0 Else stat = 1 End If Next Set objPing=Nothing Set objStatus=Nothing End Function Function checkOS(ComputerName) 'Check OS of every computer name, set strFolderToSearch to appropriate directory 'then call SearchDocs with appropriate computerName and strFolderToSearch parameters Dim objOperatingSystem Dim objOS Dim counter Dim numerr, abouterr On Error Resume Next Err.Raise 6 numerr = err.number abouterr = Err.description Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator") Set objSWbemServices = objSWbemLocator.ConnectServer _ (ComputerName & "domain", "root\cimv2", "admin", "password") objSWbemServices.Security_.ImpersonationLevel = 3 If Err.Number Then objOut.WriteLine "An error occurred with " & ComputerName _ & ": error = " & abouterr & " number = " & err.number Err.Clear End if Set colOperatingSystems = objSWbemServices.ExecQuery _ ("Select * from Win32_OperatingSystem") For Each objOperatingSystem in colOperatingSystems objOS = objOperatingSystem.Caption Next stringArray = Split(objOS) for counter=0 to UBound(stringArray) if (stringArray(counter)=strXP) then Folder = "C:\Documents and Settings" objOut2.WriteLine ComputerName & " " & stringArray(counter) & " " & Folder Exit for End if if (stringArray(counter)=str7) then Folder = "C:\Users" objOut2.WriteLine ComputerName & " " & stringArray(counter) & " " & Folder Exit for End if next Call SearchDocs(Folder, ComputerName) End Function Function SearchDocs(FolderName, ComputerName) Dim FileSize, counter, count, colFiles, objFile FileSize = 0 strFolderToSearch = FolderName Set colFiles = objSWbemServices.ExecQuery _ ("ASSOCIATORS OF {Win32_Directory.Name=" & _ "'" & strFolderToSearch & "'} Where " _ & "ResultClass = CIM_DataFile") Set objFolder = objFso.GetFolder(strFolderToSearch) Set colFiles = objFolder.Files counter = 0 For count = 0 to Ubound(FileType)-1 Ftype = FileType(count) 'On Error Resume Next For Each objFile In colFiles REM If Err.Number Then REM continue REM End if if UCase(objFso.GetExtensionName(objFile.name)) = FileType(count) Then 'Wscript.Echo "found " & objFile.Name & " in" & Subfolder.Path & "." counter = counter + 1 FileSize = FileSize + objFile.Size 'Wscript.Echo "found " & objFile.name & " in " & objFolder.Path & " ." End if Next if (counter>0) and (FileSize>0) then if (FileSize < bytesToKB) then totalSize = FileSize objOut.WriteLine ComputerName & "," & FileType(count) & "," & counter _ & "," & objFolder.Path & "," & totalSize & " bytes" end if if (FileSize >= bytesToKB) and (FileSize < bytesToMB) then totalSize = FileSize / bytesToKB objOut.WriteLine ComputerName & "," & FileType(count) & "," & counter _ & "," & objFolder.Path & "," & totalSize & " KB" end if if (FileSize >= bytesToMB) and (FileSize < bytesToGB) then totalSize = FileSize / bytesToMB objOut.WriteLine ComputerName & "," & FileType(count) & "," & counter _ & "," & objFolder.Path & "," & totalSize & " MB" end if if (FileSize >= bytesToGB) then totalSize = FileSize / bytesToGB objOut.WriteLine ComputerName & "," & FileType(count) & "," & counter _ & "," & objFolder.Path & "," & totalSize & " GB" end if end if counter=0 ShowSubfolders objFso.GetFolder(strFolderToSearch) Next End Function Sub ShowSubFolders(Folder) Dim FileSize, counter, colFiles, objFile For Each Subfolder in Folder.SubFolders Set colFiles = objSWbemServices.ExecQuery _ ("ASSOCIATORS OF {Win32_Directory.Name=" & _ "'" & Folder & "'} Where " _ & "ResultClass = CIM_DataFile") counter = 0 FileSize = 0 'Wscript.Echo Subfolder.Path Set objFolder = objFso.GetFolder(Subfolder.Path) Set colFiles = objFolder.Files On Error Resume Next For Each objFile in colFiles If Err.Number Then continue End if if UCase(objFso.GetExtensionName(objFile.name)) = Ftype Then 'Wscript.Echo "found " & objFile.Name & " in " & Subfolder.Path & "." 'totalSize = objFso.GetFile(Subfolder.Path & "\" & objFile.Name) FileSize = FileSize + objFile.Size counter = counter + 1 End if Next if (counter>0) and (FileSize>0) then if (FileSize < bytesToKB) then totalSize = FileSize objOut.WriteLine strComputer & "," & Ftype & "," & counter _ & "," & Subfolder.Path & "," & totalSize & " bytes" end if if (FileSize >= bytesToKB) and (FileSize < bytesToMB) then totalSize = FileSize / bytesToKB objOut.WriteLine strComputer & "," & Ftype & "," & counter _ & "," & Subfolder.Path & "," & totalSize & " KB" end if if (FileSize >= bytesToMB) and (FileSize < bytesToGB) then totalSize = FileSize / bytesToMB objOut.WriteLine strComputer & "," & Ftype & "," & counter _ & "," & Subfolder.Path & "," & totalSize & " MB" end if if (FileSize >= bytesToGB) then totalSize = FileSize / bytesToGB objOut.WriteLine strComputer & "," & Ftype & "," & counter _ & "," & Subfolder.Path & "," & totalSize & " GB" end if end if counter = 0 ShowSubFolders Subfolder Next End Sub 'Wscript.Echo "total number of " & FileType & " files found = " & counter & "."
-
Hey all, I have written a script that connects to a computer remotely by using the SWbemLocator and SWbemServices. Given that I'm querying both Windows XP and Windows 7 machines, I have to set the folder directories to C:\Documents and Settings and C:\Users, respectively. The script runs fine for Windows XP machines, but it returns "Path not found" for Windows 7 machines. I have checked and there is a C:\Users directory in the Win7 machines, so I don't know what wrong. I'm thinking that the connection establishment for win7 machines is different from winXP, but I haven't found any other options. Here is a snippet of the code that shows how I'm connecting: Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator") Set objSWbemServices = objSWbemLocator.ConnectServer _ (ComputerName & "domain", "root\cimv2", "admin", "password") objSWbemServices.Security_.ImpersonationLevel = 3 When I connected to a Win7 machine using the code above to find out what operating system was running on them it worked fine, but when I try to query files and folders, it returns the "Path not found" error. Let me know if you have faced a similar problem, or if you could give me any hints. Thanks....
-
SOLVED: put commas in between quotes on the objOut.WriteLine line, and output to a .csv file, which can be opened by excel.
-
So I wrote a script on Windows XP that connects to remote computers with administrative credentials, performs a number of tasks and outputs values to a .csv file. On Windows XP it ran smoothly, but when I ran the same script on a Windows 7 machine, I got path not found errors, and the output file didn't have anything. So I was wondering if the specifications for a wbemServices server connection is different in Win7. Here is a snippet of the code I'm using to connect to remote computers: Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator") Set objSWbemServices = objSWbemLocator.ConnectServer _ (ComputerName, "root\cimv2", "domain\username", "password") objSWbemServices.Security_.ImpersonationLevel = 3 Any help would be extremely appreciated. Thanks
-
Hey, here is another problem that you could probably help me with. I have exported all the data to an excel sheet, but it is in a weird format. When I write to a .xls file, the data skips columns for some reason. Here is the line: if (FileSize >= bytesToMB) and (FileSize < bytesToGB) then totalSize = FileSize / bytesToMB objOut.WriteLine ComputerName & " " & FileType & " " & counter _ & " " & objFolder.Path & " " & totalSize & " MB" It skips columns after counter and after obj.Folder.Path. I played around with the number of spaces I have in between each parameter to see if it would change anything, but didn't work. Any suggestions?
-
I have finalized the script and everything is working fine. If any of you ever run into problems related to this post, feel free to contact me and I'll show you what I've got. Thank you for all your support btw.
-
Hey all, I am trying to create a script that connects to a remote computer to get the OS that is running on it. It is a fairly simple code that I have written, and though it works for the local computer, as soon as I change the strComputer to a remote computer name it does nothing. I am querying this info out of Windows Server 2008 database. Think you can help? Here is my code: Option Explicit Dim objWMIService, objItem, colItems, counter Dim strComputer, strList, objOS, stringArray On Error Resume Next strComputer = "." strOS = "XP" str7 = "7" ' WMI Connection to the object in the CIM namespace Set objWMIService = GetObject("winmgmts:\\" _ & strComputer & "\root\cimv2") ' WMI Query to the Win32_OperatingSystem Set colItems = objWMIService.ExecQuery _ ("Select * from Win32_OperatingSystem") ' For Each... In Loop (Next at the very end) For Each objItem in colItems objOS=objItem.Caption & VbCr Next stringArray = Split(objOS) for counter=0 to UBound(stringArray) if (stringArray(counter)=strOS) then Wscript.Echo "Windows XP" Exit for End if if (stringArray(counter)=str7) then Wscript.Echo "Windows 7" Exit for End if next WSCript.Quit ' End of WMI Win32_OperatingSystem VBScript
-
Yea. I was just talking to my boss and he pointed me in the exact same direction as you. I'm about to leave work so won't be dealing with this until Tuesday, so I'll get back to you as soon as I get something. Thanks a lot and have a good weekend.
-
Hey Chris, I had a feeling that this task would require me to involve the WMI stuff, but here is a code that might be useful for this. All I need to do is to specify the UNC for the server through the strDirectory parameter. (found at: VBScript Function to Manage Windows Networks - Scripts for Administrators) Option Explicit Const retvalUnknown = 1 ' /////////////////////////////////////////////////////////////////////////////// Function CheckMp3Files( strDirectory ) Dim numMp3Files, objFso, objFolder Set objFso = CreateObject("Scripting.FileSystemObject") Set objFolder = objFso.GetFolder("c:\temp") numMp3Files = CountMp3Files( objFolder ) If( numMp3Files > 0 ) Then EXPLANATION = numMp3Files & " MP3 files detected" CheckMp3Files = False Else EXPLANATION = "No MP3 files detected" CheckMp3Files = True End If End Function ' /////////////////////////////////////////////////////////////////////////////// Function CountMp3Files( objFolder ) Dim objSubFolders, objSubFolder Dim objFiles, objFile Dim iFileNum iFileNum = 0 CountMp3Files = 0 Set objFiles = objFolder.Files If objFiles.Count <> 0 Then For Each objFile In objFiles If( InStr( UCase( objFile.Name ), ".MP3" ) <> 0 ) Then iFileNum = iFileNum + 1 End If Next End If Set objSubFolders = objFolder.SubFolders If objSubFolders.Count <> 0 Then For Each objSubFolder In objSubFolders iFileNum = iFileNum + CountMp3Files( objSubFolder ) Next End If CountMp3Files = iFileNum End Function What do you think?
-
Hey all, I am trying to write a script that connects to a number of computers and counts the number of file types (i.e. .GIF, .JPEG, .MP3, etc...) that are under a specific directory such as My Documents. I have looked around, but thought I'd come here and expand my resources for this project, since time is of the essence. If anyone could point me in the right direction, or to the right book/link, I'd appreciate it a bunch.
