Jump to content

Cleanup.cmd question


Recommended Posts

Hi

I was just woundering if there is a command to exclude one or two files when i use the:

DEL "%systemroot%\*.log"

I dont want the WindowsUpdate.log to be deleted

Or do i then have to specify ALL the different *.log files i want to be deleted?

And if i want to keep more than one file, how do i specify that?

Also what are the different "Easy Paths"? like:

%systemroot% = Windows dir

%windir% = Is this the same? (dont know)

%systemdrive% = X:\ (where x is the drive that windows is installed to)

%ProgramFiles% = Program dir (specified in winnt.sif)

%CommonProgramFiles% = Common Program files dir (can also be specified in winnt.sif)

%CDROM% = The CDRom Drive

I am doing my Cleanup.cmd file now and paths like the ones above can really help

but the main question is main priority ;)

Thanx people!

Edited by Fascix
Link to comment
Share on other sites


Here A VBS File That Should Remove What You Need

And Leave What You Want

On My Test it Left All Log File With W in Windows

Save As RemoveLog.Vbs

    Function RmLogFile

    Dim objLc : Set objLc = CreateObject("Wscript.shell")

    LACT = objLc.ExpandEnvironmentStrings("%SystemDrive%\Windows")

    F1 = LACT 

    F2 =Array ((F1 & "\0.log"), (F1 & "\1.log"), (F1 & "\2.log"), (F1 & "\3.log"), (F1 & "\4.log"),_

    (F1 & "\5.log"), (F1 & "\6.log"), (F1 & "\7.log"), (F1 & "\8.log"), (F1 & "\9.log"))

    F3 = Array  ( (F1 & "\A.log"), (F1 & "\B.log"), (F1 & "\C.log"), (F1 & "\D.log"), (F1 & "\E.log"),_

      (F1 & "\F.log"), (F1 & "\G.log"), (F1 & "\H.log"), (F1 & "\I.log"), (F1 & "\J.log"), (F1 & "\K.log"),_

      (F1 & "\L.log"), (F1 & "\M.log"), (F1 & "\N.log"), (F1 & "\O.log"), (F1 & "\P.log"), (F1 & "\Q.log"),_

      (F1 & "\R.log"), (F1 & "\S.log"), (F1 & "\T.log"), (F1 & "\U.log"),(F1 & "\V.log"), (F1 & "\W.log"),_

      (F1 & "\X.log"), (F1 & "\Y.log"), (F1 & "\Z.log"))             

               

                  On Error Resume Next

                Fso.DeleteFile (F2(0))

                Fso.DeleteFile (F2(1))

                Fso.DeleteFile (F2(2))

                Fso.DeleteFile (F2(3))

                Fso.DeleteFile (F2(4))

                Fso.DeleteFile (F2(5))

                Fso.DeleteFile (F2(6))

                Fso.DeleteFile (F2(7))

                Fso.DeleteFile (F2(8))

                Fso.DeleteFile (F2(9))   

                Fso.DeleteFile (F3(0)) 'A

                Fso.DeleteFile (F3(1)) 'B

                Fso.DeleteFile (F3(2)) 'C

                Fso.DeleteFile (F3(3)) 'D

                Fso.DeleteFile (F3(4)) 'E

                Fso.DeleteFile (F3(5)) 'F

                Fso.DeleteFile (F3(6)) 'G

                Fso.DeleteFile (F3(7)) 'H

                Fso.DeleteFile (F3(8)) 'H

                Fso.DeleteFile (F3(9)) 'J

                Fso.DeleteFile (F3(10)) 'K

                Fso.DeleteFile (F3(11)) 'L

                Fso.DeleteFile (F3(12)) 'M

                Fso.DeleteFile (F3(13)) 'N

                Fso.DeleteFile (F3(14)) '0

                Fso.DeleteFile (F3(15)) 'P

                Fso.DeleteFile (F3(16)) 'Q

                Fso.DeleteFile (F3(17)) 'R

                Fso.DeleteFile (F3(18)) 'S

                Fso.DeleteFile (F3(19)) 'T

                Fso.DeleteFile (F3(20)) 'U

                Fso.DeleteFile (F3(21)) 'V

                ' Fso.DeleteFile (F3(22)) 'W

                Fso.DeleteFile (F3(23)) 'X

                Fso.DeleteFile (F3(24)) 'Y

                Fso.DeleteFile (F3(25)) 'Z

                  End Function 

                 

RmLogFile 

For The Cdrom you need to set the varible for it

Here are 2 different ways to do it,

FOR /F "TOKENS=3" %%I IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "SourcePath" ^| FINDSTR "SourcePath"') DO SET CDROM=%%~dI
for %%i in (C: D: E: F: G: H: I: J: K: L: M: N: O: P: Q: R: S: T: U: V: W: X: Y: Z:) do if exist %%i\SETUP.exe set CDROM=%%i
Link to comment
Share on other sites

Hey Martin Zugec

I tried your command but it seems to search for the files in C:\...

So nothing happends!

I changed the %windir% to %systemroot% and i tried to specify it whit: C:\Windows in your command line...

do i need to execute it from somewhere special?

gunsmokingman

i haven´t tried yours yet. but if i want this script for say *.txt files i just change the *.log from everywhere in the script to *.txt right and then use the little ' mark on the letter of the filename i want to exclude right? And its alright to call upon this from cleanup.cmd right?

thanx

Edited by Fascix
Link to comment
Share on other sites

Martin Zugec

Okey i actually did this

I did a file called test.cmd in my root (c:\)

then i put your command line in it and ended it whit pause

then i change the *.log entries in the cmd file to *.qaz

(and WindowsUpdate.log to WindowsUpdate.qaz)

then i just created some *.qaz files and the WindowsUpdate.qaz in my windows dir

then i executed the test.cmd file and it didnt work

I did this just to test and see if it did indeed deleate just the other *.qaz files but not the WindowsUpdate.qaz

I use Windows XP sp2

Link to comment
Share on other sites

soulins Martins command is fine, the only possible changes I would make, even though they shouldn't matter as far as 'not working' is concerned is

for /f %%i in ('dir "%windir%\*.log" /b') do if %%i neq windowsupdate.log echo del /q "%%~fi"

<Edit>

When you have verified the screen output, remove 'echo '

</Edit>

Edited by Yzöwl
Link to comment
Share on other sites

I tried Martin's original command...

When I ran that batch file from the C:\ drive it gave me errors it couldn't find the particular logfile in C:\

But, when I ran it from C:\Windows it worked fine.

Hope that helps.

Edit... works like a charm for me. Re-ran it, and it didn't find anymore files. WindowsUpdate.log is still there.

Edited by enuffsaid
Link to comment
Share on other sites

To be honest, I wouldn't even bother with the batch, just paste the following into the Start > Run box and click OK

cmd /c for /f %i in ('dir "%windir%\*.log" /b') do if %i neq windowsupdate.log del /q "%~fi"

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...