Batch dos delete file size smaller
numayos
-
V.Y.Z -
V.Y.Z -
Bonjour,
I would like to create a .bat file to delete all files smaller than 100KB in a specific folder.
I have already found a way to get the size, but I can't list the files.
Do you have any tips?
Here is a snippet of code that doesn't do what I want but allows me to check the size.
@echo off
set fichier="C:\Documents and Settings\Administrateur\Bureau\Programation batch\image_tst\*.*"
for %%a in (%fichier%) do set taille=%%~za
if %taille% LSS 100000 (
echo too small. >> tst.txt
echo %taille% >> tst.txt
) else (
echo correct. >> tst.txt
echo %taille% >> tst.txt
)
Thank you in advance
I would like to create a .bat file to delete all files smaller than 100KB in a specific folder.
I have already found a way to get the size, but I can't list the files.
Do you have any tips?
Here is a snippet of code that doesn't do what I want but allows me to check the size.
@echo off
set fichier="C:\Documents and Settings\Administrateur\Bureau\Programation batch\image_tst\*.*"
for %%a in (%fichier%) do set taille=%%~za
if %taille% LSS 100000 (
echo too small. >> tst.txt
echo %taille% >> tst.txt
) else (
echo correct. >> tst.txt
echo %taille% >> tst.txt
)
Thank you in advance
Configuration: Windows XP Firefox 2.0.0.11
3 answers
-
You can always try this:
@echo off
set file="C:\Documents and Settings\Administrator\Desktop\Batch programming\image_tst\*.*"
for %%a in (%file%) do call :OKDOK "%%a"
goto :EOF
:OKDOK
set size=%~z1
echo %1 %size%
if %size% LSS 100000 (
echo file %1 too small. size=%size% >> tst.txt
) else (
echo file %1 correct. size=%size% >> tst.txt
REM
REM del /F /Q %1
REM
echo file %1 deleted >> tst.txt
)
:EOF
Just remove the "REM " in front of "del /F /Q %1" to actually delete the files larger than 100000.
In fact, the initial 4-line script calls a subroutine named OKDOK for each file found, with the file name (%%a in "" because the file name may contain spaces) as a parameter.
In the subroutine, the parameter is found in %1, just like when you pass a parameter to a batch. -
-
Yes, but I don't know how to handle this afterwards
but I will look into it more closely, I thought there was another way to do it
if anyone has an idea to retrieve the list of files from the dir??