× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Richard,

It did take a bit of research and testing to get it to where I wanted it to be. The vast majority of the code is for the error checking and the logging and comments.

If I wanted to remove that functionality and the ability to recurse subdirectories the entire DelFiles.bat script would be ONE line.

-mark

On 10/25/2018 6:18 PM, Richard Schoen via PcTech wrote:
Let's hope nobody else has to maintain that BAT file script.

All those switches give me a headache.

So this is actually logging what it deletes. I think....

Regards,
Richard Schoen
Director of Document Management
e. richard.schoen@xxxxxxxxxxxxxxx
p. 952.486.6802
w. helpsystems.com

----------------------------------------------------------------------

message: 1
date: Wed, 24 Oct 2018 13:38:40 -0400
from: mlazarus<mlazarus@xxxxxxxxxxxx>
subject: Re: [PCTECH] Recommendations for a Windows file delete
utility

Hi Gary,

After a little break from that task, I ended up with basically the approach you recommended. It includes logging and some rudimentary error checking of parms.

Thanks all for the varied suggestions.

-mark
_____________

DelFiles.bat
------------
@ECHO ON
@REM _______________________________________________________
@REM Delete files in given path that are older than x days.
@REM _______________________________________________________
@REM Parm 1: Number of days equal or older than to delete.
@REM Parm 2: Path to look in.
@REM Parm 3: Should be either TEST or DELETE.
@REM If Parm 3 is not DELETE, only the log entries are output.
The actual delete is not done.
@REM Parm 4: Specifies whether to recurse subdirectories. Allowable
values: RECURSE or NORECURSE.
@REM Notes: Folders are not inspected for age, they are skipped.
@REM - The path (parm 2) should be enclosed in double quotes, in
case there are embedded blanks.
@REM _______________________________________________________

SET DELFILESLOG=DelFiles.log

IF %1x==x GOTO ERROR1
IF %2x==x GOTO ERROR2

SET RECURSE=
IF /I %4.==RECURSE. SET RECURSE=/S


echo ***___ DELFILES started: %date% %time%: %3 mode: %2 %4 ___***>> %DELFILESLOG%

@REM This run is to output to the log.
forfiles /P %2 %RECURSE% /D -%1 /C "cmd /c if @isdir==FALSE echo @fdate
0x09 @path is at least %1 days old">> %DELFILESLOG%

echo ***___ DELFILES ended: %date% %time%: %3 mode: %2 %4 ___***>>
%DELFILESLOG%
echo .>> %DELFILESLOG%

IF /I %3. NEQ DELETE. GOTO END
@REM This run is to do the actual delete.
forfiles /P %2 %RECURSE% /D -%1 /C "cmd /c if @isdir==FALSE DEL @path"

GOTO END
::__________________________________________________

:ERROR1
PAUSE Number of days old (*GE) is mandatory.
GOTO END

:ERROR2
PAUSE Path to look in is mandatory.
GOTO END

:END
EXIT
__________

Here's the driver batch file:
DelFilesDriver.bat
------------------
@Rem _______________________________________________________
@Rem Delete files in given path that are older than x days - driver.
@Rem _______________________________________________________
@REM Parm 1: Number of days equal or older than to delete.
@REM Parm 2: Path to look in.
@REM Parm 3: Should be either TEST or DELETE.
@REM If Parm 3 is not DELETE, only the log entries are output.
The actual delete is not done.
@REM Parm 4: Specifies whether to recurse subdirectories. Allowable
values: RECURSE or NORECURSE.
@Rem _______________________________________________________

start /B /WAIT DelFiles 183 "\MyDir\Dir1\ARCHIVE" DELETE NORECURSE
start /B /WAIT DelFiles 060 "\MyDir\Dir2\ARCHIVE" DELETE NORECURSE
start /B /WAIT DelFiles 030 "\MyDir\Dir3\ARCHIVE" DELETE NORECURSE



On 9/30/2018 4:28 PM, Gary Kuznitz wrote:
You can also use this:
forfiles /p "C:\what\ever" /s /m *.* /D -<number of
days> /C "cmd /c del @path"

@PATH is the full path, including name. Note that if
you want files OLDER than 10 days, you need to specify -d "-10". -ve
means "older than", +ve means "newer than". You can also specify
DDMMYY or -DDMMYY format as the parameter to -d.

If you are using Windows 7, you can separate @PATH with just the
path, and @FILE with just the file name.
Then you can use @PATH\@FILE for the del command.

This syntax works on Win Server 2008: forfiles /P "C:\Mysql_backup" /S
/M *.sql /D -30 /C "cmd /c del @PATH"

Enjoy,

Gary

On 29 Sep 2018 at 21:41, mlazarus (mlazarus
<pctech@xxxxxxxxxxxx>) commented about [PCTECH] Recommendations for a
Windows file delet:


I am looking for recommendations for a file delete utility to be
run on a Windows server. The delete criteria would be the age of the files
within a list of folders. Each folder might have a different retention
value. It would need to run via the Windows scheduler.

A nice to have feature would be the ability to move to a different
folder instead of deleting, but not required. TIA.

-mark




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.