Computer Hope
Microsoft => Microsoft DOS => Topic started 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!
-
Try this:
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.
-
thank you!
I will give it a shot!
-
@echo off
Any input is greatly appreciated...thank you!
C:\batch>type aug.bat
@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:\>
-
@greg/bill, why go through all the trouble when you can just do
del *.asv *.sig *.spx