Click to See Complete Forum and Search --> : Making a batch file to delete MP3 files


SusieQ
June 2nd, 2001, 07:00 PM
I have a lab in a school. At present, I am having trouble with students downloading lots of Mp3 files. The other day I deleted hundreds of them from the main server. I have a batch file(installed by the technicians) on the server to delete them every 2 hours. However, some of my students have found that they can place them on c drive on the individual computers. Question, can I write a simple batch file and place it on each hard drive to do the same thing. I tried to look at the one on the server, but I don't have the rights.

shamus
June 2nd, 2001, 08:32 PM
you could do the batch file on all the machines but my suggestion would be to talk to the higher ups about implementing a proxy to limit the students access to certain sites. We use N2H2 through a universiy hook up and it has solved a lot of headaches for me.

SusieQ
June 2nd, 2001, 09:49 PM
Our board's policy is to filter nothing and this was on the advice of their lawyer. It does create a lot of headaches. Even having the batch file on the server is risky. They say it has something to do with censorship. My only concern is the intermediate students as they are the only ones interested in the Mp3 files.

ShadowKing
June 3rd, 2001, 02:29 AM
OK, I sat down and wrote you a VBS script to delete all the MP3 files on a given computer. It won't delete from removable media (e.g. Zip Disks) or Read-Only Media (e.g. CD-ROMs). It also has some commandline options if you like, so type this at the command line:
"wscript mp3killer.vbs /?"
You can feel free to rename it whatever you like, and just have it start up with the computer.

I would recommend putting in on a Network share that the users only have read-access to sot that they can't change it, and just running it from there.
"wscript \\servername\sharename\mp3killer.vbs /y"

Don't forget to use the /y option when you set it up automatically.

I would put it in the registry to start.

Anyway, you can get it here (http://www.mattlowe.com/files/mp3killer.vbs).

Feel free to look at the code and change it, but at least leave my name in there for some credit...

SusieQ
June 3rd, 2001, 07:55 AM
Thanks for the help Shadowking. I really appreciate it. I will try it.

ShadowKing
June 3rd, 2001, 01:05 PM
I actually realized last night that I forgot to add the "On Error Resume Next" statement, so I added that this morning. You may want ot get the new version.
Also, right click on it and click edit, and read the notes at the top. They will provide you with some important information...

silencio
June 3rd, 2001, 02:12 PM
Originally posted by SusieQ:
<STRONG>Our board's policy is to filter nothing and this was on the advice of their lawyer. It does create a lot of headaches. Even having the batch file on the server is risky. They say it has something to do with censorship. My only concern is the intermediate students as they are the only ones interested in the Mp3 files.</STRONG>

The heck with censoship. You should approach the issue from a utilization/security point of view. How much slower do th3 machines run when you have no space for a swapfile? What's the utilization on your internet connection? How long to students doing actual work have to wait to download stuff for homework? How many zombies are sitting on your network because some dude downloaded a keygen for windows 95 that installed sub seven on the box? These days liability has become an issue. If you ignore the problem, someone may come knocking with a multimillion dollar lawsuit.

Pogi
June 3rd, 2001, 06:21 PM
If your computer use policy plainly states that mp3's are verboten, then there should be no legal problem if you run BATs or scripts to delete them.

...Lawyers...feh...

ShadowKing
June 4th, 2001, 01:46 AM
Here is the actual text of the script for future purposes...

You will need to replace ALL of the { with a Less Than and ALL of the } with a Greater Than.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

'Mp3 Killer Script
Option Explicit
'When you add safe paths points, add them to the "SafePath" list
'Script By: Matt Lowe - matt@mattlowe.com

ReDim SafePath(50) 'you can really have as many as you want...
Dim FileTp

FileTp = "MP3" 'The Filetype to delete - You can use this to delete any filetype...

'Remember that this will delete ALL from the drives.
'I have exempted CDROM drives and removable media from the list.
'If you really want to do these, search for "Removable" and delete that part of the statement.
'We don't really want to delete THEIR Mp3s...
'Also remember that some programs USE mp3s (Like Age of Empires), so this will allow you to leave those paths out.
SafePath(0) = ""
'SafePath(1) = "c:\windows\"
'SafePath(2) = "c:\program files\microsoft office\"
'SafePath(3) = "c:\program files\age of empires\"
'SafePath(4) = ""
'SafePath(5) = ""

'{-=-=-=-=-=-=-=-=-=-=-=-=- Leave below ALONE =-=-=-=-=-=-=-=-=-=-=-=-=-}

Dim askMe 'Should we ask first?
Dim ignoreSafePath 'Should we kill them all?
Dim n, m 'My counters
Dim myDrives, mDrive 'For the Drives Collection
Dim t 'Temp variable for temp storage
Dim LocalOnly 'Flag for only local drves
Dim FilesKilled 'The number of files deleted
Dim fs 'FileSystem Object
Dim args, argument 'The Arguments
Dim goSlow 'Sleep between folders
Dim LenthOfType 'This is for filetypes that are not 3 characters...
Dim NewRoot, theRoot 'We have a different root...
dim overRead 'Should we delete read-only files also?

Set fs = CreateObject("Scripting.FileSystemObject")
Set args = wscript.Arguments

'Initialize variables
LocalOnly = False
askMe = True
ignoreSafePath = False
FilesKilled = 0
goSlow = False
LenthOfType = Len(FileTp) + 1 'for the "."
overRead = false

For Each argument In args 'Check the arguments for options
If argument = "/?" Then 'Show Help Screen
MsgBox _
"Use /y to skip the 'Are you sure?' prompt." & vbCrLf & _
"Use /f to force deleteing Read-Only files." & vbCrLf & _
"Use /i to ignore the safe paths." & vbCrLf & _
"Use /l to only delete from local drives, and not mapped network drives." & vbCrLf & _
"Use /s to go slowly and not use so much cpu time, also less noticeable." & vbCrLf & _
"Use /r:""c:\the root\path"" to just check this folder and subfolders." & vbCrLf & _
"Use /? to get this help screen.", , FileTp & " Killer Script Help"
wscript.quit
End If
If UCase(argument) = "/L" Then 'ignore mapped network drives
LocalOnly = True
End If
If UCase(argument) = "/I" Then 'ignore the excepted paths
ignoreSafePath = True
End If
If Left(UCase(argument), 3) = "/R:" Then 'ignore the excepted paths
NewRoot = True
theRoot = Right(argument, Len(argument) - 3)
End If
If UCase(argument) = "/S" Then 'Go slow
goSlow = True
End If
If UCase(argument) = "/Y" Then 'just do it
askMe = False
End If
Next

n = 0
While SafePath(n) {} "" 'Count the entered Dests so that we can parse
If Right(SafePath(n), 1) = "\" Then SafePath(n) = Left(SafePath(n), Len(SafePath(n)) - 1) 'Fix the folder names
n = n + 1
Wend

ReDim Preserve SafePath(n - 1) 'Chop off all unnecessary elements in the array

If askMe Then 'ask em
If NewRoot Then
If MsgBox("Are you sure you want to Delete all of the " & FileTp & " files from the folder below?" & vbCrLf & theRoot, vbYesNo, FileTp & " Killer") = vbNo Then wscript.quit
Else
If MsgBox("Are you sure you want to Delete all of the " & FileTp & " files on this computer?", vbYesNo, FileTp & " Killer") = vbNo Then wscript.quit
End If
End If

'For Testing...
'Create an instance of IE to output to
' Dim ie, title, page, myString
' Set ie = CreateObject("InternetExplorer.Application")
' title = "Tester..."
' page = "JavaScript:'{html}{head}{title}" & title & "{/title}{/head}{body}{/body}{/html}'"
' ie.ToolBar = False
' ie.navigate page
' Do 'wait until IE is ready for us
' Loop While ie.ReadyState {} 4
' ie.Visible = True 'show page

If NewRoot Then
KillFiles (fs.GetFolder(theRoot))
Else
Set myDrives = fs.Drives
For Each mDrive In myDrives
'Here we check to make sure there is a disk in the drive and its not a CD-ROM or a Removable Disk (e.g. Zip Disk)
If mDrive.IsReady And mDrive.DriveType {} "CD-ROM" And mDrive.DriveType {} "Removable" Then
If LocalOnly = False Or Not (mDrive.DriveType = "Remote") Then 'If its a local drive or network with local only being false, then
t = mDrive.Path
KillFiles (fs.GetFolder(t))
End If
End If
Next
End If
If askMe Then MsgBox FileTp & " Deletion Complete: " & vbCrLf & FilesKilled & " files deleted.", , FileTp & " Killer"
'_________________________________________________ __________________________________________________ _____________________

Sub KillFiles(folderobj)
Dim file 'the thing to check
Dim subfolder 'the next place to search
On Error Resume Next
If Not ignoreSafePath Then
If InSafePath(folderobj.Path) Then Exit Sub
End If
If goSlow Then sleep 50
For Each file In folderobj.Files ' check all files in current folder

'For Testing...
'ie.document.body.innerhtml = "Checking File: " & file.Path & "{br}Filename: " & file.Name & "{br}File type: " & Right(file.Name, LenthOfType) & myString

If UCase(Right(file.Name, LenthOfType)) = "." & UCase(FileTp) Then 'Delete the nasty file. Die. Die. Die.
'For Testing...
'myString = myString & "{br}{Font color=red}Deleted:{/font} " & file.Path
if overRead then 'we need to remove the readonly bit from the dest file
if file.attributes and 1 then 'If file is read only then
file.Attributes = file.Attributes and not 14000 and not 1 'remove the bit
end if
end if

file.Delete
FilesKilled = FilesKilled + 1
End If
Next

' do the same for any subfolders
For Each subfolder In folderobj.subfolders
KillFiles subfolder
Next
On Error GoTo 0
End Sub
'_________________________________________________ __________________________________________________ _____________________

Private Function InSafePath(FolderName)
InSafePath = False
For n = 0 To UBound(SafePath)
t = Len(SafePath(n))
'For Testing...
'if msgbox(UCase(Left(SafePath(n), t)) & " = " & UCase(Left(FolderName, t)),vbyesno,"Continue?") = vbno then wscript.quit
If UCase(Left(SafePath(n), t)) = UCase(Left(FolderName, t)) Then
InSafePath = True
End If
Next
End Function

condor
June 4th, 2001, 05:17 AM
I have to say this is a very nice script..

but I think this will do the same thing..

del /s *.mp3

just put the batch file in drive c: and it will clear all the mp3 from the HDD

Enjoy <IMG SRC="smilies/wink.gif" border="0">

3fingersalute
June 4th, 2001, 06:26 AM
Condor's is quick and to the point, I would just run it locally on each machine upon first boot of the day before the stundents get there, because a batch can be easily cancelled if they see it running!

condor
June 4th, 2001, 06:34 AM
you can start it minimized or from the registry ..

in HKLM\Software\Microsoft\Windows\CurrentVersion\Run Serivces

Creat a string called MP3clean
give it the value of

call c:\cleanmp3.bat

close regedit

edit the batch files properties to run minimized.


Good luck ..

ShadowKing
June 4th, 2001, 01:38 PM
Originally posted by Condor:
<STRONG>I have to say this is a very nice script..

but I think this will do the same thing..

del /s *.mp3

just put the batch file in drive c: and it will clear all the mp3 from the HDD

Enjoy <IMG SRC="smilies/wink.gif" border="0"></STRONG>

Thanks Condor, but the reason for the script was so that it would do all of the drives c,d,n... and would allow exceptions. My big concern with deleting ALL of a certain filetype is that some programs may actually USE mp3s (Age of Empires being the only one I can think of right now...) and it may break the program to delete its mp3s. This will allow those exceptions...

Though I will admit that your solution is much simpler. <IMG SRC="smilies/biggrin.gif" border="0">

http://forums.windrivers.com/cgi-bin/forum1/noncgi
June 5th, 2001, 02:21 AM
If you have especificos archives that you do not want to eliminate vast with leaving them in advance hidden, is to say to these archives to give "attrib +h *.mp3" would be left them outside the reach of the lethal one: "del /s *.mp3"

<IMG SRC="smilies/eek.gif" border="0"> <IMG SRC="smilies/eek.gif" border="0"> <IMG SRC="smilies/eek.gif" border="0">

condor
June 5th, 2001, 02:34 AM
Originally posted by ShadowKing:
<STRONG>

Thanks Condor, but the reason for the script was so that it would do all of the drives c,d,n... and would allow exceptions. My big concern with deleting ALL of a certain filetype is that some programs may actually USE mp3s (Age of Empires being the only one I can think of right now...) and it may break the program to delete its mp3s. This will allow those exceptions...

Though I will admit that your solution is much simpler. <IMG SRC="smilies/biggrin.gif" border="0"></STRONG>

hey I really meant it on the nice script..

I think it's pretty useful for some applications.

However, on a school computer it's uncalled for 99% of the time.

and as for setting attributes - again, you're drifting away from the topic..

it's a school computer, people d/l ****.. they wanna clean it every day. that's it..

nothing fancy - and so is my solution <IMG SRC="smilies/smile.gif" border="0">

ShadowKing
June 5th, 2001, 01:34 PM
Originally posted by Condor:
<STRONG>
However, on a school computer it's uncalled for 99% of the time.

nothing fancy - and so is my solution <IMG SRC="smilies/smile.gif" border="0"></STRONG>

True, though I would also use the /f option (for either solution) to delete the read-only ones too. As a former CS student, it would take me 2 minutes to mark the file as Read-Only and have it stay around...

Quiet Thunder
June 5th, 2001, 02:53 PM
Create a text file named "yes" with simply "Y" in it. Keep the txt file along with the bat file. Then, create a batch file with the lines:


:MAIN
del *.mp3 <yes.txt

GOTO MAIN

This will save you from having to type in y everytime you come across a mp3 to confirm the deletion. That way, you can run and walk away. (You will have to empty the recycle bin though. Unless anyone can figure out how to have the bat file do it.)

http://forums.windrivers.com/cgi-bin/forum1/noncgi
June 6th, 2001, 03:52 AM
Hey, ShadowKing,

your script is very good,
but they assault doubts to me,

script also includes the Hidden files?

<IMG SRC="smilies/eek.gif" border="0"> <IMG SRC="smilies/eek.gif" border="0"> <IMG SRC="smilies/eek.gif" border="0">

ShadowKing
June 6th, 2001, 05:55 PM
Originally posted by Denied Access:
<STRONG>Hey, ShadowKing,

your script is very good,
but they assault doubts to me,

script also includes the Hidden files?

<IMG SRC="smilies/eek.gif" border="0"> <IMG SRC="smilies/eek.gif" border="0"> <IMG SRC="smilies/eek.gif" border="0"></STRONG>

Yes, it does hidden files. VBS doesn't really care whether they are hidden or not...

ShadowKing
June 6th, 2001, 06:02 PM
OK here's the deal:

Well, I showed the script to my supervisor and asked what he thought, and he said "Oh, its mediocre".

And I said "Mediocre?!? Like you could have done any better!"

His response was "It's not remotable."

"OK wise guy, we'll just see..."

So anyway here (http://www.mattlowe.com/files/mp3Killer2.vbs) is the remotable version.

You just need to make a text file that has a list of each computer by name on each line. You also need to specify different options for the remote script, so you can run yours with the /d {isplay what is going on} option and just run the remote one with the /y and /o option.

I first started with scanning the administrative shares of each machine on the network, but I realized with a network of 60 computers it would never finish. So instead, I copy the script over to the C$ root and then start it as a remote process on that machine. When it is finished it deletes itself. Takes less than 5 seconds, and lets each individual machine do its own work...

I tested this on a Windows 2000 domain with a few computers and it ran pretty well, It should definitely run on NT also if IE 5 or above is installed. I am unsure about Win9x. It uses wbem, so who knows. If someone wants to try it out on a 9x network, let me know.

ShadowKing
June 6th, 2001, 08:14 PM
Update:

OK I talked to the guy who helped develope the wmi/wbem stuff and he said if you want it to run on 9x/NT4 then you need to install this (http://www.microsoft.com/downloads/release.asp?ReleaseID=18490).

So if you want to use the remotable script with Win9x boxes, get the wmicore.exe and install it on the workstations. You can then also do any other wmi stuff you want.

Quiet Thunder
June 8th, 2001, 07:41 AM
Originally posted by Quiet Thunder:
<STRONG>Create a text file named "yes" with simply "Y" in it. Keep the txt file along with the bat file. Then, create a batch file with the lines:


:MAIN
del *.mp3 <name of text file

GOTO MAIN

This will save you from having to type in y everytime you come across a mp3 to confirm the deletion. That way, you can run and walk away. (You will have to empty the recycle bin though. Unless anyone can figure out how to have the bat file do it.)</STRONG>


It won't show my post correctly.
send me an email and I can send you a batch file to do this, the forum is messing up some of the code.
put <yes.text next to *.mp3
and put goto main on the next line

ShadowKing
June 11th, 2001, 01:24 PM
Originally posted by ShadowKing:
<STRONG>Update:

OK I talked to the guy who helped develope the wmi/wbem stuff and he said if you want it to run on 9x/NT4 then you need to install this (http://www.microsoft.com/downloads/release.asp?ReleaseID=18490).

So if you want to use the remotable script with Win9x boxes, get the wmicore.exe and install it on the workstations. You can then also do any other wmi stuff you want.</STRONG>

BTW if you are using SMS in your company then WMI should already be installed.