Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search for files Script 2

Status
Not open for further replies.

pbanacos

IS-IT--Management
Apr 21, 2006
34
US
Hello,

Is there a way to search for MP3 files using WSH and VBscript? Im trying to get the total number of files and how much space they take up on a users system. Any Help with this would be much Appreciated!!

I was thinking that the WIN32_Directory may be useful for this?


Thanks

 
You could just use

dir /s/w *.mp3

It will scroll off the screen but what you get at the very end is what you're looking for - the number of files and the total amout of space taken up by the mp3 files.
 
Code:
'==========================================================================
'
' NAME: ReportMP3.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 8/28/2006
'
' COMMENT: <comment>
'
'==========================================================================

'---------------------------------------------------------------------------------------
'
'	Name:		getfoldersize.vbs
'	Version:	1.0
'	Date:		3/1/2004
'	Author:		Mark D. MacLachlan
'	Description:	getfoldersize.vbs calculates the size of all subfolders within
'			a folder
'	
'---------------------------------------------------------------------------------------
Dim Sizereport
   rootfolder = Inputbox("Enter directory/foldername: " & _
                         chr(10) & chr(10) & "(i.e. C:\Program Files or " & _
                         "\\Servername\C$\Program Files)" & chr(10) & chr(10), _
                         "Getfoldersize", "C:\4myRide")

   outputfile = "c:\4myRide\MP3size_" & Day(now) & Month(now) & Year(now) & ".txt"

   Set fso = CreateObject("scripting.filesystemobject")
   if fso.fileexists(outputfile) then fso.deletefile(outputfile)


report = ""


'Run checkfolder
MP3SizeReport = CheckFolder(rootfolder, 0)

Function CheckFolder(objCurrentFolder, SizeReport)
      Set oFolder = fso.GetFolder(objCurrentFolder)
      For Each oFile In oFolder.files
		   	If oFile.Type = "MP3 Format Sound" Then
		    	Report = Report & vbCrLf & oFile.Name & "        " &  oFile.Size
		    	SizeReport = SizeReport + oFile.Size
		    End If
	  Next
    
    'Recurse through all of the folders
    For Each objNewFolder In oFolder.subFolders
        CheckFolder objNewFolder, SizeReport
    Next
    CheckFolder = SizeReport
End Function

Report = Report & vbCrLf & "Total MP3 Size =" & (MP3SizeReport/1024\1024) & "MB"

Set ts = fso.CreateTextFile (outputfile, ForWriting)
ts.write report

'Message when finished
   Set WshShell = CreateObject("WScript.Shell")
   Finished = Msgbox ("Script executed successfully, results can be found in " & Chr(10) _
                     & outputfile & Chr(10) & Chr(10) _
                     & "Do you want to view the results now?", 65, "Script executed successfully!")
   if Finished = 1 then WshShell.Run "notepad " & outputfile

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Thanks for the previous post XWB

Is there a way just to display total memory used
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top