jlester3 Posted June 30, 2011 Posted June 30, 2011 Hi all,I'm glad I found this forum. I was looking for help with this issue but the deployment discussions are great.I made a simple bat file to clear out temp files for users but I'd like to add a bit of information output to it.I made it for both Win7 and XP, if the directory doesn't exist it doesn't do anything so I just added both OS directories. If anyone has any other directories to suggest to clean out please let me know. I've read a bit about prefetch not needing to be cleaned but a peer likes to empty it so I added it.I'd like to be able to count the files (and files in subfolders) in each temp folder and display a total number of files cleaned once the script is completed. (Or display the number of files before deletion if that's tricky)Here is what I put together, it's really basic. Any ideas on how to add a total number of files cleaned output to it?Thanks for any help.del /s /q "c:\windows\prefetch\*.*"del /s /q "c:\windows\temp\*.*"del /s /q "%homepath%\Appdata\Local\Temp\*.*"del /s /q "c:\temp\*.*"del /s /q "%homepath%\Local Settings\Temporary Internet Files\*.*"del /s /q "%homepath%\Local Settings\Temp\*.*
jaclaz Posted June 30, 2011 Posted June 30, 2011 Something like:@ECHO OFFSETLOCAL ENABLEEXTENSIONSSETLOCAL ENABLEDELAYEDEXPANSIONSET /A Counter=0FOR %%A IN ("c:\windows\prefetch\*.*" "c:\windows\temp\*.*" "%homepath%\Appdata\Local\Temp\*.*" "c:\temp\*.*" "%homepath%\Local Settings\Temporary Internet Files\*.*" "%homepath%\Local Settings\Temp\*.* ) DO (CALL :do_count %%ACALL :do_del %%A)GOTO :EOF:do_countFOR /F %%B IN ('dir /b %1') DO (SET /A Counter+=1ECHO !Counter!)GOTO :EOF:do_delECHO del %1GOTO :EOFjaclaz
jlester3 Posted July 1, 2011 Author Posted July 1, 2011 Thank you for your response.I spent a bunch of time trying to figure this out too. It seems like too much of a hassle just to show a number and show the bat is worthwhile to a user though. If they see a performance increase that's enough for me.
Yzöwl Posted July 1, 2011 Posted July 1, 2011 Here's a script which should do at least what you require!@ECHO OFFSETLOCAL ENABLEEXTENSIONSFOR %%! IN ( "X:\Path To\Some Directory" "X:\Same Path To\Another Directory" "X:\Different Path To\A Folder") DO ( CALL :CN "%%~f!\*" # CALL ECHO=Of %%#%% file(s^) located in %%~f! DEL/Q "%%~f!\*.*" CALL :CN "%%~f!\*" _ CALL SET/A £=%%#%% - %%_%% CALL ECHO=%%£%% were successfully deleted! CALL SET/A T +=%%£%%)ECHO=ECHO=%T% files were removed during the cleanup process.ECHO=PAUSEGOTO :EOF:CNSET "%2=0"FOR %%$ IN (%1) DO SET/A %2 +=1All you need to do is change the example paths I've provided, (lines 4-6), to the ones you're cleaning.
gunsmokingman Posted July 1, 2011 Posted July 1, 2011 Here a VBS script1:\ Run Csript2:\ Ask if you want to continue or quit3:\ If Continue will attempt to delete all files in the listed Dir Array4:\ Show The Total Amount Of Files Deleted And The Amont Deleted In Mb Or KbCleanUp.vbs'-> Objects To Use uring RuntimeDim Act :Set Act = CreateObject("Wscript.Shell")Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")'-> Pathway VariblesDim Win :Win = Act.ExpandEnvironmentStrings("%Windir%")Dim UsD :UsD = Act.ExpandEnvironmentStrings("%UserProfile%")'-> Array For DirectoriesDim Dir :Dir = Array( _ Win & "\prefetch", _ Win & "\temp", _ UsD & "\Appdata\Local\Temp",_ "c:\temp", _ UsD & "\Local Settings\Temporary Internet Files", _ UsD & "\Local Settings\Temp")'-> Varibles To Be Used During RuntimeDim C1, C2, File, Folder, Lne, Obj, Reply Lne = " -------------------------------------------------------------- "'-> To Make Sure This Runs In Cscript Only If InStr(1,WScript.FullName,"cscript",1) Then YesNo() ElseIf InStr(1,WScript.FullName,"wscript",1) Then MsgBox vbTab & "Error Wrong Scripting Engine" & vbCrLf & _ "To Use This Script It Must Be Run Under Cscript.exe" & vbCrLf & _ "Right Click This Script And Select Command Prompt" & vbCrLf & _ "Option, To Open This Script Correctly",4128,"Error Wrong Engine" End If '-> Yes Or No Function Function YesNo()'-> Show List Of Folder To Delete Files WScript.StdOut.WriteLine " Directories To Clean Up" & vbCrLf & Lne For Each Obj In Dir If Fso.FolderExists(Obj) Then WScript.StdOut.WriteLine " " & Obj End If Next WScript.StdOut.WriteBlankLines 1 Do While Len(Reply) < 5 WScript.StdOut.WriteLine Lne WScript.StdOut.WriteLine " Do You Want To Continue With Deleting All" WScript.StdOut.WriteLine " Above Listed Directories Files. This Script" WScript.StdOut.WriteLine " Will Attempt To Delete All Files In All Sub" WScript.StdOut.WriteLine " Directories. Type Yes To Continue And No To" WScript.StdOut.WriteLine " Exit And Do Nothing" WScript.StdOut.WriteLine Lne WScript.StdOut.WriteBlankLines 1 Reply = Wscript.StdIn.ReadLine'-> User Confirms If InStr(1,Reply, "yes",1) Then For Each Obj In Dir If Fso.FolderExists(Obj) Then Recursive Fso.GetFolder(Obj) End If Next '-> Converts Number To Either Mb Or Kb If C2 > 1048576 Then C2 = FormatNumber(C2 / 1048576,2) C2 = C2 & " Mb" Else C2 = FormatNumber(C2 / 1024,2) C2 = C2 & " Kb" End If '-> End Of Script WScript.StdOut.WriteLine " Total Files Deleted : " & C1 WScript.StdOut.WriteLine " Total Sizes Deleted : " & C2 WScript.StdOut.WriteLine " Press Enter To Exit" Do While WScript.StdIn.AtEndOfLine WScript.Quit() Loop'-> User Cancel ElseIf InStr(1,Reply, "no",1) Then WScript.Quit End If Loop End Function'-> Loop Threw All Sub Folders Function Recursive(Loc) WScript.StdOut.WriteLine Lne & vbCrLf & _ " Procesing Folder : " & Loc.Name & vbCrLf & lne On Error Resume Next For Each File In Loc.Files C1 = C1 + 1 C2 = Int(C2) + Int(File.Size) WScript.StdOut.WriteLine File.Name Fso.DeleteFile(File.Path),True Next For Each Folder In Loc.subFolders Recursive Folder Next End FunctionRename CleanUp.vbs.txt to CleanUp.vbs to make activeCleanUp.vbs.txt
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now