• Announcements

    • xper

      MSFN Sponsorship and AdBlockers!   07/10/2016

      Dear members, MSFN is made available via subscriptions, donations and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, become a site sponsor and ads will be disabled automatically and by subscribing you get other sponsor benefits.
Sign in to follow this  
Followers 0
Fascix

Cleanup.cmd question

21 posts in this topic

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
0

Share this post


Link to post
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
0

Share this post


Link to post
Share on other sites
For /f "usebackq" %%i IN (`dir /b %windir%\*.log`) DO If %%i NEQ WindowsUpdate.log del /q %%i

0

Share this post


Link to post
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
0

Share this post


Link to post
Share on other sites

Works fine on mine pc, I tried it... What OS are you using?

The script is not dependent on actual path.

0

Share this post


Link to post
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

0

Share this post


Link to post
Share on other sites

Ok, try this:

For /f "usebackq" %%i IN (`dir /b %windir%\*.log`) DO If %%i NEQ WindowsUpdate.log echo %%i >> c:\test.log

And post the test.log to see what happens

0

Share this post


Link to post
Share on other sites

Hmmm okey i tríed it but the test.log is empty!!!?

Edited by Fascix
0

Share this post


Link to post
Share on other sites

For /f "usebackq" %%i IN (`dir /b %windir%\*.log`) DO If %%i NEQ WindowsUpdate.log echo %%i
Pause

And try to post the content of cmd window

0

Share this post


Link to post
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
0

Share this post


Link to post
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
0

Share this post


Link to post
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"

0

Share this post


Link to post
Share on other sites

I tried both from my desktop and it didnt work.

the test files I made where

New.log

Document.log

Text.log

New Text Document.log

newTextDocument.log

This Vbs I ran From My Desktop and it worked.

It is a re edit of the earlier vbs it was late here for me and the first

one i forgot some things.

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

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

    Dim Fso : Set Fso = CreateObject("Scripting.Filesystemobject") 

    Function RmLogFile

    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 

Act.popup "Completed",3,"remove Log Files", 0 + 32

0

Share this post


Link to post
Share on other sites

Last go then, tested on several machines from several locations

@echo off
pushd %systemroot%
for %%a in ("*.log") do if %%a neq windowsupdate.log del /q "%%~a"
popd
goto :eof

Hope this is it now!

0

Share this post


Link to post
Share on other sites

He he i have been busy with other things and when i look now you guys have really put some effort in this.

Thanx i will try all your tips!

EDIT: I have now tested your vbs script Gunsmokingman and your "last" command line" tip Yzöwl. Both worx like a charm but i think the command line is better, less code and i can keep it inside my cleanup.cmd file right?

Its okey to just paste in the

@echo off
pushd %systemroot%
for %%a in ("*.log") do if %%a neq windowsupdate.log del /q "%%~a"
popd
goto :eof

inside my cleanup.cmd file right?

or do i need to remove the @echo off and goto:eof??

or do i just need to call this seperate file from cleanup.cmd? and if so do i need to add something to ether file so it returns to the cleanup.cmd file when finished?

Thanx again for all your help guys :hello:

EDIT:

By the way take a look at this:

cmdow @ /HID
shutdown.exe -r -f -t 60 -c "Windows XP will now restart in 1 minute..."
net user aspnet /delete

RD /S /Q "%AllUserProfile%\Delade dokument\"
RD /S /Q "%AllUserProfile%\Application Data\Microsoft\Media Index\"
DEL "%AllUserProfile%\Application Data\Microsoft\User Account Pictures\Default Pictures\*.*"

DEL "%UserProfile%\Mina Dokument\Min musik\*.*"
DEL "%UserProfile%\Mina Dokument\Mina bilder\*.*"
DEL "%UserProfile%\SendTo\E-postmottagare.MAPIMail"
DEL "%UserProfile%\SendTo\Komprimerad mapp.ZFSendToTarget"
DEL "%UserProfile%\SendTo\Mina dokument.mydocs"
DEL "%UserProfile%\SendTo\Skrivbord (skapa genväg).DeskLink"

RD /S /Q "%ProgramFiles%\ComPlus Applications\"
RD /S /Q "%ProgramFiles%\microsoft frontpage\"
RD /S /Q "%ProgramFiles%\WindowsUpdate\"
RD /S /Q "%ProgramFiles%\xerox\"

DEL "%CommonProgramFiles%\Microsoft Shared\Stationary\*.*"

DEL "%systemroot%\*.bak"
DEL "%systemroot%\*.bmp"
DEL "%systemroot%\*.old"
DEL "%systemroot%\*.tmp"
DEL "%systemroot%\clock.avi"
DEL "%systemroot%\control.ini"
DEL "%systemroot%\desktop.ini"
DEL "%systemroot%\win.ini"
DEL "%systemroot%\OEWABLog.txt"
DEL "%systemroot%\setuplog.txt"

RD /S /Q "%systemroot%\$hf_mig$\"
RD /S /Q "%systemroot%\addins\"
RD /S /Q "%systemroot%\Config\"
RD /S /Q "%systemroot%\Connection Wizard\"
RD /S /Q "%systemroot%\Cursors\"

DEL "%systemroot%\Driver Cache\i386\drivers.cab"
DEL "%systemroot%\Driver Cache\i386\sp2.cab"

RD /S /Q "%systemroot%\Help\Tours\"
DEL "%systemroot%\system32\tourstart.exe"

DEL "%systemroot%\inf\*.PNF"
DEL "%systemroot%\inf\mdm*.inf
DEL "%systemroot%\Media\*.*"
RD /S /Q "%systemroot%\msapps\"
RD /S /Q "%systemroot%\mui\"
RD /S /Q "%systemroot%\RegisteredPackages\"
DEL "%systemroot%\SoftwareDistribution\Download\*.*"
DEL "%systemroot%\Temp\*.*"
DEL "%systemroot%\Web\Wallpaper\*.*"

RD /S /Q "%systemroot%\system32\3com_dmi\"
RD /S /Q "%systemroot%\system32\1025\"
RD /S /Q "%systemroot%\system32\1028\"
RD /S /Q "%systemroot%\system32\1031\"
RD /S /Q "%systemroot%\system32\1037\"
RD /S /Q "%systemroot%\system32\1041\"
RD /S /Q "%systemroot%\system32\1042\"
RD /S /Q "%systemroot%\system32\1054\"
RD /S /Q "%systemroot%\system32\2052\"
RD /S /Q "%systemroot%\system32\3076\"
RD /S /Q "%systemroot%\system32\dhcp\"
DEL "%systemroot%\system32\dllcache\*.*"
RD /S /Q "%systemroot%\system32\DirectX\Dinput\"
RD /S /Q "%systemroot%\system32\export\"
RD /S /Q "%systemroot%\system32\inetsrv\"
RD /S /Q "%systemroot%\system32\ShellExt\"
RD /S /Q "%systemroot%\system32\SoftwareDistribution\"
RD /S /Q "%systemroot%\system32\xircom\"

RD /S /Q "%UserProfile%\Favoriter\Länkar\"
DEL "%systemroot%\Favoriter\*.*"

DEL "%systemroot%\Start-meny\Program\Fjärrhjälp.lnk"
DEL "%systemroot%\Start-meny\Program\Outlook Express.lnk"
DEL "%systemroot%\Start-meny\Program\Tillbehör\Adressbok.lnk"
DEL "%systemroot%\Start-meny\Program\Tillbehör\Guiden Programvarukompatibilitet.lnk"
DEL "%systemroot%\Start-meny\Program\Tillbehör\Synkronisera.lnk"
DEL "%systemroot%\Start-meny\Program\Tillbehör\Upptäck Windows XP.lnk"

DEL "%UserProfile%\Lokala inställningar\Temp\*.*"

RD /S /Q "%systemdrive%\Drivers\"
RD /S /Q "%systemdrive%\Install\"

@echo off
pushd %systemroot%
for %%a in ("*.log") do if %%a neq windowsupdate.log del /q "%%~a"
popd
goto :eof

EXIT

Does it seems to be in order? (bare in mind some directories and filenames are in Swedish :P )

Thanx

Edited by Fascix
0

Share this post


Link to post
Share on other sites

You can safely remove the @echo off and goto :eof from my bit at the end.

0

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.