View Full Version : deleting files older than...


Markus Mannheim
09-26-2005, 09:08 AM
Hi,

on an ftp Server I am running a script which clears all files in subfolders
of the users:

:: Variablen
set datei=d:\scripte\folders.txt
set start=d:\ftp
set start2=ftp

setlocal
d:
cd\
cd %start2%
dir /a:d /b >%datei%
FOR /F %%G IN (%datei%) DO (
cd %%G
pushd %start%\%%G%
cd\
cd %start2%\%%G%
for /F "tokens=1-3,* delims=\" %%A in ('dir /B /S /AD^|sort /R') do (
if "" NEQ "%%D" RD /Q /S "%%A\%%B\%%C\%%D")
del %start%\%%G%\*.* /q /f
copy d:\scripte\readme.txt ./y

d:
cd\
cd %start2%
popd)
del %datei%
set start=
set start2=

Now this script deletes all files whenever I run it via "Sheduled Tasks".
Because our users are working in different countries, the files should
remain for 24 hours, instead.
Some of you may have an idea how to read the date of a file and compare it
with the actual date?

For help thanks in advance,

Markus

Michael Bednarek
09-26-2005, 10:27 AM
On Mon, 26 Sep 2005 10:08:24 +0200, "Markus Mannheim"
<markus@spam-hater.invalid> wrote in
microsoft.public.win2000.cmdprompt.admin:

>on an ftp Server I am running a script which clears all files in subfolders
>of the users:
>
>:: Variablen
>set datei=d:\scripte\folders.txt
>set start=d:\ftp
>set start2=ftp
[snip]
>Now this script deletes all files whenever I run it via "Sheduled Tasks".
>Because our users are working in different countries, the files should
>remain for 24 hours, instead.
>Some of you may have an idea how to read the date of a file and compare it
>with the actual date?

Trivial with the right CLI, 4NT in this case:
DEL /[d-1@%_time,1980/1/1] /S /X /Y d:\ftp\*.*
This will delete files older than yesterday at the time when the script
runs; IOW: if it's now 26-Sep-2005 19:24 it will delete files modified
on or before 25-Sep-2005 19:24. It will also remove all empty
directories.

4NT's Date Ranges are documented at
<http://jpsoft.com/help/dateranges.htm>. 4NT's DEL command is documented
at <http://jpsoft.com/help/del.htm>. 4NT is a commercial product.

--
Michael Bednarek http://mbednarek.com/ "POST NO BILLS"

Timo Salmi
09-26-2005, 09:08 PM
Markus Mannheim wrote:
(snip)

45} How can I find out how many days old a file is?
60} How do I delete all but most recent 20 files in a folder?
136348 Sep 25 13:47 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:ts@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html