Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

Cleanup.cmd question

- - - - -

  • Please log in to reply
20 replies to this topic

#1
Fascix

Fascix

    The Swedish Steel

  • Member
  • Pip
  • 94 posts
  • Joined 10-May 05
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, 10 June 2005 - 04:12 AM.



How to remove advertisement from MSFN

#2
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,438 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
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




GunSmokingMan



#3
Martin Zugec

Martin Zugec

    MSFN Expert

  • Member
  • PipPipPipPipPipPip
  • 1,373 posts
  • Joined 24-January 04
For /f "usebackq" %%i IN (`dir /b %windir%\*.log`) DO If %%i NEQ WindowsUpdate.log del /q %%i

Like my opinions? Read Deployment/scripting blog
Like my scripts? They are under DrinkWare license :)

#4
enuffsaid

enuffsaid

    Friend of MSFN

  • Member
  • PipPipPipPipPip
  • 866 posts
  • Joined 26-December 03
Nice command there, Martin! :thumbup

#5
Martin Zugec

Martin Zugec

    MSFN Expert

  • Member
  • PipPipPipPipPipPip
  • 1,373 posts
  • Joined 24-January 04
Simple commands = nice command :)
Like my opinions? Read Deployment/scripting blog
Like my scripts? They are under DrinkWare license :)

#6
enuffsaid

enuffsaid

    Friend of MSFN

  • Member
  • PipPipPipPipPip
  • 866 posts
  • Joined 26-December 03
It sure beats the 30+ lined VB script. ;)

#7
Fascix

Fascix

    The Swedish Steel

  • Member
  • Pip
  • 94 posts
  • Joined 10-May 05
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, 10 June 2005 - 06:23 AM.


#8
Martin Zugec

Martin Zugec

    MSFN Expert

  • Member
  • PipPipPipPipPipPip
  • 1,373 posts
  • Joined 24-January 04
Works fine on mine pc, I tried it... What OS are you using?

The script is not dependent on actual path.
Like my opinions? Read Deployment/scripting blog
Like my scripts? They are under DrinkWare license :)

#9
Fascix

Fascix

    The Swedish Steel

  • Member
  • Pip
  • 94 posts
  • Joined 10-May 05
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

#10
Martin Zugec

Martin Zugec

    MSFN Expert

  • Member
  • PipPipPipPipPipPip
  • 1,373 posts
  • Joined 24-January 04
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
Like my opinions? Read Deployment/scripting blog
Like my scripts? They are under DrinkWare license :)

#11
Fascix

Fascix

    The Swedish Steel

  • Member
  • Pip
  • 94 posts
  • Joined 10-May 05
Hmmm okey i tríed it but the test.log is empty!!!?

Edited by Fascix, 10 June 2005 - 07:29 AM.


#12
Martin Zugec

Martin Zugec

    MSFN Expert

  • Member
  • PipPipPipPipPipPip
  • 1,373 posts
  • Joined 24-January 04
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
Like my opinions? Read Deployment/scripting blog
Like my scripts? They are under DrinkWare license :)

#13
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,587 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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, 10 June 2005 - 09:56 AM.


#14
enuffsaid

enuffsaid

    Friend of MSFN

  • Member
  • PipPipPipPipPip
  • 866 posts
  • Joined 26-December 03
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, 10 June 2005 - 10:15 AM.


#15
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,587 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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"


#16
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,438 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
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




GunSmokingMan



#17
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,587 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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!

#18
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,438 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
Work from my desktop :thumbup


GunSmokingMan



#19
Fascix

Fascix

    The Swedish Steel

  • Member
  • Pip
  • 94 posts
  • Joined 10-May 05
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, 11 June 2005 - 02:32 PM.


#20
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,587 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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

#21
BoardBabe

BoardBabe

    MSFN Expert

  • Member
  • PipPipPipPipPipPip
  • 1,419 posts
  • Joined 04-October 04
It should be

del /q "%WinDir%\%%i"

at the end...
BoardBabe




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users