Computer Hope

Microsoft => Microsoft DOS => Topic started by: Aug3r on March 19, 2010, 09:41:52 AM

Title: batch delete
Post by: Aug3r on March 19, 2010, 09:41:52 AM
I'm relatively new to BAT file programming but experienced in another language...
With the compiler I'm using, it leaves me with 4-5 junk files that over a couple days of multiple versions..gets kinda extensive.
So I wrote this batch file:

@echo off
COLOR 0A
echo WHAT UP G33K??


set /p file_variable="WADDAH WE DO'IN HERE ... "
del /s "file_variable" \*.asv
del /s "file_variable" \*.sig
del /s "file_variable" \*.spz
pause
dir c:\windows

once this is opened, I drag the folder into the window & hit enter.
everything works ok, except for one thing...i only want the folders i specified to be cleared of such "junk files" and nothing else.
cuz it turns out one of my "junk" files..also happens to share a similar file extension with an important windows file....which has made me have to re-install a couple times.  I removed the extension from this version (.sm2)...but if I can designate "ONLY this folder & any subfolders" i could resume the full clean...so to speak.

any input is greatly appreciated...thank you!
Title: Re: batch delete
Post by: gregflowers on March 19, 2010, 12:31:26 PM
Try this:


Code: [Select]
set file_variable=%1
del /s "%file_variable%\*.asv"


%1 is the varible that is passed to the batch file on the command line as a parameter,
There also shoud not be spaces in the path. The variable names are enclosed in by the percent signs.
Title: Re: batch delete
Post by: Aug3r on March 22, 2010, 11:59:33 AM
thank you!
I will give it a shot!
Title: Re: batch delete
Post by: greg on March 22, 2010, 09:20:20 PM
@echo off

Any input is greatly appreciated...thank you!


C:\batch>type aug.bat
Code: [Select]
@echo off
echo WHAT UP G33K?
Rem We will assume all bad files are in c:\windows
cd  c:\windows
dir /b *.asv *.sig *.spx
dir /b *.asv  >  c:\temp\badfiles.txt
dir /b *.sig >>  c:\temp\badfiles.txt
dir /b *.spx  >>  c:\temp\badfiles.txt
pause
echo type  c:\temp\badfiles.txt
type c:\temp\badfiles.txt
pause
for  /f "delims=" %%i in (c:\temp\badfiles.txt) do (
echo  %%i
del "%%i"
)
del c:\temp\badfiles.txt
dir /b *.asv *.sig *.spx
cd \

Output:

C:\batch>aug.bat
WHAT UP G33K?
bad.asv
bad.sig
bad.spx
Press any key to continue . . .
type  c:\temp\badfiles.txt
bad.asv
bad.sig
bad.spx
Press any key to continue . . .
 bad.asv
 bad.sig
 bad.spx
File Not Found
C:\>
Title: Re: batch delete
Post by: ghostdog74 on March 22, 2010, 09:36:00 PM
@greg/bill, why go through all the trouble when you can just do
Code: [Select]
del *.asv *.sig *.spx