Scripts Thread, VBScript: Access Computers on a network and count specific files types in Coding and Web Development; Hey all,
I am trying to write a script that connects to a number of computers and counts the number ...
-
23rd September 2011, 04:08 PM #1
- Rep Power
- 0
VBScript: Access Computers on a network and count specific files types
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.
-
-
IDG Tech News
-
23rd September 2011, 05:04 PM #2 You want to do a Vbscript with a wmi query looking specifically file the files types or extensions. The queries look a bit like a SQL query. There is probably a nice way to do it in Powershell as well but I don't know that off hand.
-
Thanks to ChrisH from:
umass (23rd September 2011)
-
23rd September 2011, 05:52 PM #3
- Rep Power
- 0
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?
-
-
23rd September 2011, 05:55 PM #4 That does the same sort of thing but a WMI query looks a bit like this:
Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colFiles = objWMIService. _
ExecQuery("Select * from CIM_DataFile where Extension = 'mp3'")
For Each objFile in colFiles
Wscript.Echo "File Name: " & objFile.Name & "." & objFile.Extension
Wscript.Echo "Path: " & objFile.Path
Next They are usually chosen between because of speed. Your example is better in some circumstances than mine although I can't think of a good example.
-
-
23rd September 2011, 06:05 PM #5
- Rep Power
- 0
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.

Originally Posted by
ChrisH
That does the same sort of thing but a WMI query looks a bit like this:
Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colFiles = objWMIService. _
ExecQuery("Select * from CIM_DataFile where Extension = 'mp3'")
For Each objFile in colFiles
Wscript.Echo "File Name: " & objFile.Name & "." & objFile.Extension
Wscript.Echo "Path: " & objFile.Path
Next They are usually chosen between because of speed. Your example is better in some circumstances than mine although I can't think of a good example.
-
-
23rd September 2011, 10:33 PM #6 Have a look a the Gnuwin32 package - a port of unix goodies that windows is sadly lacking in.
the 'find' command-line utility could be what you need.
-
-
7th October 2011, 04:00 PM #7
- Rep Power
- 0
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.
-
SHARE: 
Similar Threads
-
By SW-ICT in forum Hardware
Replies: 5
Last Post: 21st June 2011, 02:02 PM
-
By Stuart_C in forum School ICT Policies
Replies: 5
Last Post: 3rd September 2009, 06:41 PM
-
By speckytecky in forum General Chat
Replies: 4
Last Post: 4th July 2008, 12:06 PM
-
By TechSupp in forum Wireless Networks
Replies: 3
Last Post: 1st January 2008, 03:18 PM
-
By ITWombat in forum School ICT Policies
Replies: 3
Last Post: 2nd October 2006, 08:33 AM
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules