I currently have a batch file that does two things
1) It deletes specific files (.jpg & .pdf) older than X days old in a specific directory and sub folders
2) It scans subfolder of the same directory (above) and delete specific files extension (.jpg & .pdf)
This runs daily on a 2008R2 Server, it is (probably) not fancy, but it gives me the results I want and as I am happy to leave it as it is.
What I would like to do is to add a third module to my batch file which will delete any specific files (.jpg) over a certain size say 1536kb (this size may change) when the batch file runs. If I can get a small script to do this I may even opt to run this as a separate script and run it several times a day. The path the files reside in is
m:\global\pix\pix
Can anybody offer any suggestions please?
Third module to a batch file
Moderator: DosItHelp
Re: Third module to a batch file
The unit of file sizes in batch is bytes. You can determine them using the ~z modifier of FOR variables. E.g.
Just insert an IF statement in order to process files greater than a certain size.
(replace ECHO with DEL to delete the files)
Problem is that batch only supports signed integers with a width up to 32 bits. That means the greatest number that you can compare numerically is 2147483647.
Steffen
Code: Select all
for %%i in ("m:\global\pix\pix\*.jpg") do echo %%~zi (%%i)
Just insert an IF statement in order to process files greater than a certain size.
Code: Select all
for %%i in ("m:\global\pix\pix\*.jpg") do if %%~zi gtr 1572864 echo "%%i"
(replace ECHO with DEL to delete the files)
Problem is that batch only supports signed integers with a width up to 32 bits. That means the greatest number that you can compare numerically is 2147483647.
Steffen
Re: Third module to a batch file
Thanks eGerman, I will have a play and see how I get on
-
- Posts: 240
- Joined: 04 Mar 2014 11:14
- Location: germany
Re: Third module to a batch file
use an empty Folder and robocopy.
Phil
Code: Select all
@echo off
setlocal
set "T=%temp%\DF%time::=%"
md "%T%" ||exit /b 1
PushD "%T%"
:List
rem Delim=TAB
rem minage - not before
for /f "tokens=3 delims= " %%D in (
'robocopy /L /fp /np /njh /njs /mir "m:\global\pix\pix" "%T%" "*.jpg" "*.pdf" /minage:25 /min:1572864 /XX /NDL'
) do echo del "%%D"
popD
rd "%T%"
exit /b 0
Phil
Re: Third module to a batch file
pieh-ejdsch wrote:use an empty Folder and robocopy.Code: Select all
@echo off
setlocal
set "T=%temp%\DF%time::=%"
md "%T%" ||exit /b 1
PushD "%T%"
:List
rem Delim=TAB
rem minage - not before
for /f "tokens=3 delims= " %%D in (
'robocopy /L /fp /np /njh /njs /mir "m:\global\pix\pix" "%T%" "*.jpg" "*.pdf" /minage:25 /min:1572864 /XX /NDL'
) do echo del "%%D"
popD
rd "%T%"
exit /b 0
Phil
Hi Phil
Can you explain what each line is doing , I have an idea of bits of it but not most of it
Re: Third module to a batch file
xendistar wrote:Thanks eGerman, I will have a play and see how I get on
It would repay the kindness if you let aGerman know how you got on.
Re: Third module to a batch file
foxidrive wrote:xendistar wrote:Thanks eGerman, I will have a play and see how I get on
It would repay the kindness if you let aGerman know how you got on.
I had every intention of replying to eGerman (and anybody else who offered a solution once I had tried them), it has just taken me longer to try eGerman's script than I had intended. I asked Phil the question regarding his script simply as I was reading his contribution over a cup of tea and to be perfectly honest I could not make head of tail of it (I understood just about eGerman's script).
In regards to eGerman's script it worked perfectly in the tests I have run on a folder with 142 mixed files types, of which 72 are .jpg and 27 of those .jpg have a size greater than 1572864. When I get the time next week I will try the script for real.
My thanks to eGerman