piXelatedEmpire Posted June 10, 2006 Posted June 10, 2006 using my cleanup.cmd file, I wish to delete all .tmp and log files created within the WINDOWS directory and it's subfolders. I also wish to delete all empty folders. What commands would I use to achieve this?Thanks for any assistance
Yzöwl Posted June 10, 2006 Posted June 10, 2006 They wanted 'all subfolders' too!FOR %%? IN (log tmp) DO (DEL/A/S/F/Q "%SYSTEMROOT%\*.%%?")
T D Posted June 11, 2006 Posted June 11, 2006 (edited) Orcd %systemroot%DEL *.LOG /SDEL *.TMP /SEDIT I forgot you only wanted %systemroot%There is a command you can use with RD to del empty folders but I'm not sure.DEL *LOG*.TXT /SI'd recommend this for a clean install only. Some files don't end with .log, but have log in the name. See Yzöwl's post below. Edited June 11, 2006 by T D
Yzöwl Posted June 11, 2006 Posted June 11, 2006 (edited) @ T D, why would someone want to remove all files with the string 'log' contained anywhere within its name?There is no logic, in telling people to delete all of their:logon scriptslogo design criteriadialog resourcescompetition slogansmusic catalogs*'ology study documents.I really think you should apologize.There are methods available for removing empty directories using batch files but they are not considered efficient or stable, (vbscript would perform the task much better). There is also the question of what constitutes an 'empty folder'.There are many empty directories within %windir% which are required by the system, therefore I am not willing to provide code here to do that. Edited June 11, 2006 by Yzöwl
T D Posted June 11, 2006 Posted June 11, 2006 (edited) Oh, sorry, I realise my mistake. But if it was on a fresh install, this wouldn't matter. I'll change my first post. And some logfiles aren't *.log, but say for a program, maybe something like outlookerrlog.txt or setuplog.txtIt was only a suggestion.And OK, there are better ways, but I'm not exactly going to list all of them if one of them already works as it should, am I? And I'm not an expert on vbscripting.And there wouldn't be a file called "apologize" on your computer even if it does have the words "log" in it. Edited June 11, 2006 by T D
Yzöwl Posted June 11, 2006 Posted June 11, 2006 (edited) Oh, sorry, I realise my mistake. But if it was on a fresh install, this wouldn't matter. I'll change my first post. And some logfiles aren't *.log, but say for a program, maybe something like outlookerrlog.txt or setuplog.txtIt was only a suggestion.Yes it wouldbasic list:winlogon.exe, netlogon.dll, eventlog.dll, seclogon.dll, logon.scr, logonui.exe, camlog30.bmp, chglogon.exe, convlog.exe, iislog51.dll, iologmsg.dll, iscomlog.dll, loghours.dll, login.cmd, logman.exe, logoff.exe, logscrpt.dll, logtemp.sql, logui.ocx, mqlogmgr.dll, msdtclog.dll, relog.exe, smlogcfg.dll, smlogsvc.exe, txflog.dll, usrlogon.cmd, zlogic.cyz, mslogo.jpg, oemlogo.gif, loginkey.dll, eqnlogr.exe, log.dll, reslog32.dll, xlog.exe, obelog.dll, mplogo.gif, mplogoh.gif, logagent.exe, wmdmlog.dllAnd OK, there are better ways, but I'm not exactly going to list all of them if one of them already works as it should, am I? And I'm not an expert on vbscripting.You haven't listed any ways!I have already stated, and believe me when I say it, there is no efficient way of using standard batch commands to delete 'all empty folders'And there wouldn't be a file called "apologize" on your computer even if it does have the words "log" in it.I really do hope that you are not suggesting anything untoward about my character. Take a look at what you've said, look at my fully explained point about *log* then you can really apologize, because you are very definitely wrong! Edited June 11, 2006 by Yzöwl
T D Posted June 11, 2006 Posted June 11, 2006 (edited) And there wouldn't be a file called "apologize" on your computer even if it does have the words "log" in it.I really do hope that you are not suggesting anything untoward about my character. Take a look at what you've said, look at my fully explained point about *log* then you can really apologize, because you are very definitely wrong!That last part was a joke, the one about apologize, OK? And besides, that command only deletes txt files anyway.You haven't listed any ways!I have already stated, and believe me when I say it, there is no efficient way of using standard batch commands to delete 'all empty folders'Like I said, you can use batch files (even if it is inefficient). I don't know any other way; I'm only stating a possible method. If you have a better method, then say that (eg vbscripting) is better! Don't turn it into an argument. If it won't work, then say and I'll change my first post. Edited June 11, 2006 by T D
Yzöwl Posted June 11, 2006 Posted June 11, 2006 (edited) Your new line may say txt but before I corrected you it said DEL *LOG*.* /S.<Edit>Run this vbscript, see how many output folders it identifies:Function NumberOfFilesInFolder(FolderName) Dim fso, f, f1, fc, CountFiles Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.GetFolder(FolderName) Set fc = f.Files CountFiles = 0 For Each f1 in fc CountFiles = CountFiles + 1 Next NumberOfFilesInFolder = CountFilesEnd FunctionFunction NumberOfFoldersInFolder(FolderName) Dim fso, f, f1, fc, CountFolders Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.GetFolder(FolderName) Set fc = f.SubFolders CountFolders = 0 For Each f1 in fc CountFolders = CountFolders + 1 Next NumberOfFoldersInFolder = CountFoldersEnd FunctionFunction TraverseSubFolders(StartFolderName) Dim fso, f, f1, sf, nFil, nFol Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.GetFolder(StartFolderName) Set sf = f.SubFolders For Each f1 in sf nFil = NumberOfFilesInFolder(f1) nFol = NumberOfFoldersInFolder(f1) if (CLng(nFil) = 0) And (CLng(nFol) = 0) Then Wscript.Echo f1 End If TraverseSubFolders(f1) NextEnd FunctionFunction TraverseFolders(StartFolderName) Dim fso, f, f1, sf, nFil, nFol Set fso = CreateObject("Scripting.FileSystemObject") If (fso.FolderExists(StartFolderName)) Then Set f = fso.GetFolder(StartFolderName) nFil = NumberOfFilesInFolder(f) nFol = NumberOfFoldersInFolder(f) if (CLng(nFil) = 0) And (CLng(nFol) = 0) Then Wscript.Echo f End If TraverseSubFolders(f) Else Wscript.Echo "Folder " & StartFolderName & " not found" Wscript.Quit End IfEnd FunctionDim WshShell, StartAtFolderSet WshShell = WScript.CreateObject("WScript.shell")StartAtFolder = WshShell.ExpandEnvironmentStrings("%SystemRoot%")TraverseFolders StartAtFolder</Edit><Edit2>If you really didn't like my original for command, you could also have used the more simpleDEL/A/S/F/Q "%SYSTEMROOT%\*.LOG" "%SYSTEMROOT%\*.TMP"since DEL actually takes multiple arguments!</Edit2> Edited June 11, 2006 by Yzöwl
T D Posted June 11, 2006 Posted June 11, 2006 Your new line may say txt but before I corrected you it said DEL *LOG*.* /S.Like I've been saying for the past few posts, I made a mistake. Don't point out every one. C'mon!I should use vbscript instead of batch files now, it seems so much more useful.
gunsmokingman Posted June 11, 2006 Posted June 11, 2006 A VBS Script to delete the log files in Systemroot and it sub folders.It will not delete these log files\windows\sti_trace.log\windows\wiadebug.log\windows\wiaservc.log\windows\windowsupdate.log\WINDOWS\SoftwareDistribution\ReportingEvents.log\WINDOWS\system32\CatRoot2\edb.logSave As DeleteLogFile.vbsOn Error Resume Next strComputer = "." Dim Act, Fso, SysRoot Set Act = CreateObject("Wscript.Shell") Set Fso = CreateObject("Scripting.FileSystemObject") SysRoot = Act.ExpandEnvironmentStrings("%SystemRoot%")'/-> WMI QUERRY Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colFileList = objWMIService.ExecQuery _ ("ASSOCIATORS OF {Win32_Directory.Name='" & SysRoot & "'} Where ResultClass = CIM_DataFile")'/-> VARIBLES Dim colFiles ,Folder, objF,Subfolder Dim colFileList, objFile'/-> LOOP THAT USES THE WMI QUERRY FOR THE WINDOW DIRECTORY For Each objFile In colFileList If objFile.Extension = "log" Then Fso.DeleteFile(objFile.Name) End If Next'/-> START THE SUB FOLDER COLLECTION IN THE WINDOW DIRECTORY ShowSubfolders Fso.GetFolder(SysRoot) Function ShowSubFolders(Folder) On Error Resume Next For Each Subfolder in Folder.SubFolders Set colFiles = Subfolder.Files For Each objF in colFiles If InStr(objF.Path,".log") Then Fso.DeleteFile(objF.Path) End If Next ShowSubFolders Subfolder Next Exit Function End Function Act.Popup "Completed Script", 5,"Finished", 0 + 32
T D Posted June 13, 2006 Posted June 13, 2006 It will not delete these log filesQUOTE\windows\sti_trace.log\windows\wiadebug.log\windows\wiaservc.log\windows\windowsupdate.log\WINDOWS\SoftwareDistribution\ReportingEvents.log\WINDOWS\system32\CatRoot2\edb.logCan you give me a brief overview of the importance of these files (other than windowsupdate.log and edb.log)?Thanks.
gunsmokingman Posted June 13, 2006 Posted June 13, 2006 It will not delete these log filesQUOTE\windows\sti_trace.log\windows\wiadebug.log\windows\wiaservc.log\windows\windowsupdate.log\WINDOWS\SoftwareDistribution\ReportingEvents.log\WINDOWS\system32\CatRoot2\edb.logCan you give me a brief overview of the importance of these files (other than windowsupdate.log and edb.log)?Thanks.All I know about those files is the script can not delete them, as why I do not know.Try this script it will make a text file of the files not deleted by the script.On Error Resume Next strComputer = "." Dim Act, Dtop, Fso, SysRoot, Ts Set Act = CreateObject("Wscript.Shell") Set Fso = CreateObject("Scripting.FileSystemObject") SysRoot = Act.ExpandEnvironmentStrings("%SystemRoot%") Dtop = Act.SpecialFolders("Desktop") Set Ts = Fso.CreateTextFile(Dtop & "\DeletedLog.txt") Ts.WriteLine Now()'/-> WMI QUERRY Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colFileList = objWMIService.ExecQuery _ ("ASSOCIATORS OF {Win32_Directory.Name='" & SysRoot & "'} Where ResultClass = CIM_DataFile")'/-> VARIBLES Dim colFiles ,Folder, objF,Subfolder Dim colFileList, objFile'/-> LOOP THAT USES THE WMI QUERRY FOR THE WINDOW DIRECTORY For Each objFile In colFileList If objFile.Extension = "log" Then Fso.DeleteFile(objFile.Name) If Fso.FileExists(objFile.Name) = True Then Ts.writeline "Cannot Delete This File : " & Chr(187) & " " & objFile.Name End If End If Next'/-> START THE SUB FOLDER COLLECTION IN THE WINDOW DIRECTORY ShowSubfolders Fso.GetFolder(SysRoot) Function ShowSubFolders(Folder) On Error Resume Next For Each Subfolder in Folder.SubFolders Set colFiles = Subfolder.Files For Each objF in colFiles If InStr(objF.Path,".log") Then Fso.DeleteFile(objF.Path) If Fso.FileExists(objF.Path) = True Then Ts.writeline "Cannot Delete This File : " & Chr(187) & " " & objF.Path End If End If Next ShowSubFolders Subfolder Next Exit Function End Function Ts.close Act.Run("Notepad.exe " & Dtop & "\DeletedLog.txt"), 1,True Fso.DeleteFile(Dtop & "\DeletedLog.txt"), True
RogueSpear Posted June 14, 2006 Posted June 14, 2006 I always archive all of the log files to a 7-Zip file and then delete them. I've found that you just never know when you might want to take a peek at them for one reason or another.
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