1.

Solve : Delete??

Answer» HI I own a Game Server and I need a Batch that will DELETE any file inside the folder the batch is in that has a name longer than 12 chars..

Example

It will be in the "characters" folder and it needs to delete any .txt file that is named ANYTHING longer than 12 chars.

C:\batch>type great12.bat
Code: [Select]@echo off
dir /b *.txt > 12long.txt
awk.exe "length > 12" 12long.txt > great12.txt

for /f "delims=" %%i in (great12.txt) do echo %%i

rem for /f "delims=" %%i in (great12.txt) do del %%i
Output:

C:\batch> great12.bat
2awkinfile.txt
awkinfile.txt
awlinfile.txt
caavsetupLog.txt
christmas.txt
endresult.txt
finalziplist.txt
Instruct_for.txt
list_of_program_files.txt
outinfile.txt
testfilnam.txt
xsplfiles.txt
C:\batch>@OP:

you might want to put rem before this line:
Code: [Select]for /f "delims=" %%i in (great12.txt) do echo %%i

and remove the rem from this line:
Code: [Select]rem for /f "delims=" %%i in (great12.txt) do del %%i
Quote from: BillRichardson on December 29, 2009, 12:19:26 PM
C:\batch>type great12.bat
Code: [Select]@echo off
dir /b *.txt > 12long.txt
awk.exe "length > 12" 12long.txt > great12.txt

for /f "delims=" %%i in (great12.txt) do echo %%i

rem for /f "delims=" %%i in (great12.txt) do del %%i

you can use gawk's FILENAME variable, IF you have gawk.
Code: [Select]C:\test>gawk "length(FILENAME) > 4 {print FILENAME;nextfile}" *.txt


Discussion

No Comment Found