solution how to change the dir to del in the

December 11, 2009 at 09:35:12
Specs: Windows XP
I am looking for the solution how to change the dir to del in the following command. Anyone can help me?

------------------
Batch File Name: Delete-Files.bat
Code: MS-DOS
OS: Windows XP Professional, SP2
------------------

@echo off
REM 12 December 2009
REM
REM The purpose of this program is to delete files by a user specified Old-Than-x-Day value.
REM
REM The core code (111 lines) was taken off the internet.
REM Credit goes to: Chrispie & Dtech10.
REM Web Site: http://www.computing.net/programmin...
REM
REM All the necessary modifications and additions were made by: Pete Soski
REM [SomeoneReallyNeedsToLearnHowNotToPostHisEmail@Yahoo.com]
REM
REM This code has been drafted and tested on Windows XP Professional, SP2.
REM Compatibility testing on different OS's will be necessary.
REM
REM Packaged by default, this program will only run a DIR command, not a DEL command.
REM See comments towards the bottom of the code to change into a DEL program.
REM
REM This program can do the following:
REM - Accept a value that purges files by date. Files older then the value are deleted.
REM - Accept a path in which to begin searching
REM - The path can be a network path.
REM - Accept value; namely an extension, allowing wildcards to limit selection
REM - Program will list all deleted files
REM - Program will list all evaluated files
REM - Accept value to enable or disable sub-directory searching.
REM - Accept value to enable or disable Read-Only file deletion.
REM - Program will give the number of files deleted
REM - Program will give the number of files skipped over
REM - Program will give total number of files processed.
REM - Program Start Time will be posted
REM - Program Finish Time will be posted.
REM - The program will also calculate and post elapsed time.
REM

CLS
:HouseKeeping
REM Start Time
REM This will load the current time into 'Start' variables.
REM.
Set Start_Time=%time%
FOR /f "tokens=1-3 delims=:." %%a in ('echo %time%') do (
set Start_hh=%%a
set Start_mm=%%b
set Start_ss=%%c
)
FOR /f "tokens=1-3 delims=: " %%a in ('time /t') do (set Start_Meridan=%%c)
Echo Start Time: %Start_hh%:%Start_mm%:%Start_ss% %Start_Meridan%

Set Delete_Counter=0
Set FChecked_Counter=0
Set Total_Files=0
Set Finish_day=0
SET OLDERTHAN=%1
SET FileDir=%~2
SET EXT=%3
SET Sub_Dir=%4
SET Force_Check=%5
IF NOT DEFINED OLDERTHAN GOTO SYNTAX
IF NOT DEFINED FileDir GOTO SYNTAX
IF NOT DEFINED EXT GOTO SYNTAX
IF NOT DEFINED Force_Check Goto Get_Date
IF DEFINED Force_Check Goto Read_Only
Goto Exit

:Read_Only
IF %Force_Check%==1 set Force_Delete=/F
Goto Get_Date

REM Get Todays Date
:Get_Date
FOR /f "tokens=1-4 delims=/- " %%a in ('date /t') do (
set xx=%%a
set mm=%%b
set dd=%%c
set yyyy=%%d
)

set /A mm=%mm%+0
if %dd%==01 set dd=1
if %dd%==02 set dd=2
if %dd%==03 set dd=3
if %dd%==04 set dd=4
if %dd%==05 set dd=5
if %dd%==06 set dd=6
if %dd%==07 set dd=7
if %dd%==08 set dd=8
if %dd%==09 set dd=9
set /A dd=%dd%+0
set /A dd=%dd% - %OLDERTHAN%
set /A yyyy=%yyyy%+0

:LOOPDATE

if /I %dd% GTR 0 Goto DONE
set /A mm=%mm% - 1
if /I %mm% GTR 0 Goto ADJUSTDAY
set /A mm=12
set /A yyyy=%yyyy% - 1

:ADJUSTDAY
if %mm%==1 Goto SET31
if %mm%==2 Goto LEAPCHK
if %mm%==3 Goto SET31
if %mm%==4 Goto SET30
if %mm%==5 Goto SET31
if %mm%==6 Goto SET30
if %mm%==7 Goto SET31
if %mm%==8 Goto SET31
if %mm%==9 Goto SET30
if %mm%==10 Goto SET31
if %mm%==11 Goto SET30
if %mm%==12 Goto SET31

:SET31
set /A dd=31 + %dd%
Goto LOOPDATE

:SET30
set /A dd=30 + %dd%
Goto LOOPDATE

:LEAPCHK
set /A tt=%yyyy% %% 4
if not %tt%==0 Goto SET28
set /A tt=%yyyy% %% 100
if not %tt%==0 Goto SET29
set /A tt=%yyyy% %% 400
if %tt%==0 Goto SET29

:SET28
set /A dd=28 + %dd%
Goto LOOPDATE

:SET29
set /A dd=29 + %dd%

:DONE
if /i %dd% LSS 10 set dd=0%dd%
if /I %mm% LSS 10 set mm=0%mm%

:Search_Type
IF NOT DEFINED Sub_Dir GOTO No_Sub_Dir
If %Sub_Dir%==0 Goto :No_Sub_Dir
If %Sub_Dir%==1 Goto :Sub_Directory
Else Goto :No_Sub_Dir

:No_Sub_Dir
for %%i in (%FileDir%\%EXT%) do (
set FileName=%%i
call :PROCESSFILE %%~ti)

Goto Print_Results

:Sub_Directory
for /R %FileDir% %%i in (%EXT%) DO (
set FileName=%%i
call :PROCESSFILE %%~ti)

Goto Print_Results

:Print_Results
Echo.
Echo The number of files deleted : %Delete_Counter%
Echo.
Echo The number of files passed over : %FChecked_Counter%
Echo.
Echo The Total number of files processed: %Total_Files%
Echo.
Goto Get_Finish_Time

:Get_Finish_Time
REM This will load the current time into 'Finish' variables.
REM.
FOR /f "tokens=1-3 delims=:." %%a in ('echo %time%') do (
set Finish_hh=%%a
set Finish_mm=%%b
set Finish_ss=%%c
)
FOR /f "tokens=1-3 delims=: " %%a in ('time /t') do (set Finish_Meridan=%%c)
Goto Calculate_Time

:Calculate_Time
REM Calculate the difference in time between Start and Finish times
REM.

IF %Start_ss% GTR %Finish_ss% (
set /A Finish_ss=%Finish_ss%+60
set /A Finish_mm=%Finish_mm%-1
)
set /A Diff_ss=%Finish_ss%-%Start_ss%

IF %Start_mm% GTR %Finish_mm% (
set /A Finish_mm=%Finish_mm%+60
set /A Finish_hh=%Finish_hh%-1
)
set /A Diff_mm=%Finish_mm%-%Start_mm%

IF %Start_hh% GTR %Finish_hh% (
set /A Finish_hh=%Finish_hh%+24
set Finish_day=1
)
set /A Diff_hh=%Finish_hh%-%Start_hh%

REM The follow will adjust for negative time values.
REM.
REM if %Diff_hh% LSS 0 (set /A Diff_hh=%Diff_hh%+23)
REM if %Diff_mm% LSS 0 (set /A Diff_mm=%Diff_mm%+59)
REM if %Diff_ss% LSS 0 (set /A Diff_ss=%Diff_ss%+59)
REM The following will compensate for single digit results.
REM.
if %Diff_hh%==0 set Diff_hh=00
if %Diff_hh%==1 set Diff_hh=01
if %Diff_hh%==2 set Diff_hh=02
if %Diff_hh%==3 set Diff_hh=03
if %Diff_hh%==4 set Diff_hh=04
if %Diff_hh%==5 set Diff_hh=05
if %Diff_hh%==6 set Diff_hh=06
if %Diff_hh%==7 set Diff_hh=07
if %Diff_hh%==8 set Diff_hh=08
if %Diff_hh%==9 set Diff_hh=09
if %Diff_mm%==0 set Diff_mm=00
if %Diff_mm%==1 set Diff_mm=01
if %Diff_mm%==2 set Diff_mm=02
if %Diff_mm%==3 set Diff_mm=03
if %Diff_mm%==4 set Diff_mm=04
if %Diff_mm%==5 set Diff_mm=05
if %Diff_mm%==6 set Diff_mm=06
if %Diff_mm%==7 set Diff_mm=07
if %Diff_mm%==8 set Diff_mm=08
if %Diff_mm%==9 set Diff_mm=09
if %Diff_ss%==0 set Diff_ss=00
if %Diff_ss%==1 set Diff_ss=01
if %Diff_ss%==2 set Diff_ss=02
if %Diff_ss%==3 set Diff_ss=03
if %Diff_ss%==4 set Diff_ss=04
if %Diff_ss%==5 set Diff_ss=05
if %Diff_ss%==6 set Diff_ss=06
if %Diff_ss%==7 set Diff_ss=07
if %Diff_ss%==8 set Diff_ss=08
if %Diff_ss%==9 set Diff_ss=09
Goto Print_Time

:Print_Time
REM This will return the results to the user.
REM.
Set End_Time=%time%
Echo.
Echo The program started at: %Start_Time% %Start_Meridan%
Echo The program ended at : %End_Time% %Finish_Meridan%
Echo hh:mm:ss.mm
Echo.
Echo This is the amount of time elapsed from the
Echo start to the end of the program executing.
Echo.
Echo %Diff_hh%:%Diff_mm%:%Diff_ss%
Echo hh:mm:ss
Echo. Number of Days Elapsed: %Finish_day%

Goto Reset_Variables

:Reset_Variables

REM The following will reset the variables used by this program.
REM A.K.A. cleaning up.
set mm=
set yyyy=
set dd=
set thedate=
set xx=
set tt=
set FileDir=
set FileName=
set ext=
set OlderThan=
set Sub_Dir=
set Delete_Counter=
set Total_Files=
set FChecked_Counter=
set Force_Check=
set Force_Delete=
set Diff_hh=
set Diff_mm=
set Diff_ss=
set Start_hh=
set Start_mm=
set Start_ss=
set Start_Meridan=
set Finish_hh=
set Finish_mm=
set Finish_ss=
set Finish_Meridan=
set mm=
set hh=
set ss=
set Start_Time=
set End_Time=
set Finish_day=
Goto Exit

:SYNTAX
Echo.
Echo USAGE:
Echo Delete-Files.bat [Days] [Dir] [File-Extension] [Sub-Directory Search] [Read_Only_Delete]
Echo Delete-Files x C:\ wildcard.ext 0 or 1 0 or 1
Echo.
Echo Mandatory: "Delete-Files [Days] [Dir] [File-Extension]"
Echo "Delete-Files 180 C:\Temp *.Log"
Echo.
Echo Where:
Echo [Days] = Number
Echo Determines the number of days previous to Today that will be selected.
Echo.
Echo Example: "Delete-Files.bat 5 C:\Temp *.LOG" Deletes all LOG files older than 5 days.
Echo.
Echo [Dir] = Path
Echo "Delete-Files.bat 120 C:\Temp *.LOG" Deletes all LOG files from the
Echo "C:\Temp" directory that are older than 120 days.
Echo.
Echo [File-Extension] = wildcards and extension
Echo This detemined which files or file-types that will be deleted.
Echo.
Echo Wildcards are allowed. [* ?]
Echo Examples: [*.* , *.LOG , ~*.*]
Echo.
Echo Example: "Delete-Files.bat 15 C:\Temp *.LOG"
Echo Example: This will delete all LOG files older than 15 days from C:\Temp
Echo.
Echo [Sub-Directory Search] = 1 or 0
Echo.
Echo Possible values {0 , 1}
Echo A value of "0" or blank, will not search sub-directory for possible files
Echo to delete.
Echo.
Echo A value of "1" and only "1", will search every directory underneath the
Echo the specified directory. If C:\Temp and "1" then C:\Temp and C:\Temp\srbackup\..
Echo will be searched and evaluated for file deletion.
Echo.
Echo Example: "Delete-Files.bat 5 C:\Temp *.LOG 1"
Echo This will search C:\Temp and ALL sub-directories for *.LOG files, older
Echo then 5 days and delete them.
Echo.
Echo Example: "Delete-Files.bat 5 C:\Temp *.LOG"
Echo This will search ONLY C:\Temp for *.LOG files older than 5 days and
Echo delete those that qualify.
Echo.
Echo [Read_Only_Delete] = 1 or 0
Echo WARNING!
Echo The Sub-Directory Search value must be present for this to work.
Echo.
Echo This fifth control-switch will force the deletion of Read-Only files.
Echo Enter a "1" if the forced deletion of Read-Only files is wanted.
Echo Leave the value empty or specify "0" to keep Read-Only untouched.
Echo.
Echo Example: "Delete-Files.bat 120 C:\Temp *.LOG 0 1"
Echo This will delete all LOG files, over 120 days, in C:\Temp, and will
Echo be deleted even if Read-Only. This switch will delete regular and Read-Only files.
Echo.
Echo Example: "Delete-Files.bat 120 C:\Temp *.LOG 0 0"
Echo This will delete all LOG files, over 120 days, in C:\Temp, and
Echo will NOT delete Read-Only files.
Echo.
Echo Example: "Delete-Files.bat 120 C:\Temp *.LOG 1 1"
Echo This will delete all LOG files, over 120 days, in C:\Temp, in all subdirectories of C:\Temp
Echo and will delete files Read-Only and regular.
Echo.

Echo Delete-Files.bat [Days] [Dir] [File-Extension] [Sub-Directory Search] [Read_Only_Delete]
Echo Delete-Files x C:\ wildcard.ext 0 or 1 0 or 1
Echo.
Echo Mandatory: "Delete-Files [Days] [Dir] [File-Extension]"
Echo "Delete-Files 180 C:\Temp *.Log"
Echo.
Echo -- End of help --

GOTO Exit

:PROCESSFILE
set temp=%1
set fyyyy=%temp:~6%

if /I %fyyyy% LSS 100 set fyyyy=20%fyyyy%
if /I %fyyyy% GTR 2069 set fyyyy=19%temp:~6%

set fmm=%temp:~0,2%
set fdd=%temp:~3,2%

:: +*************************************+
:: | This is where the files are deleted |
:: | Change the DIR command to DEL to |
:: | delete. DIR is used for test. |
:: +*************************************+

if /I %yyyy%/%mm%/%dd% GEQ %fyyyy%/%fmm%/%fdd% (
Echo "- The selected file will be deleted."
Echo "%FileName%"
Dir %Force_Delete% "%FileName%"
Set /A Delete_Counter=%Delete_Counter%+1
Set /A Total_Files=%Total_Files%+1
Echo.
) Else (
Echo "The selected file does not qualify for deletion."
Echo "%FileName%"
Set /A FChecked_Counter=%FChecked_Counter%+1
Set /A Total_Files=%Total_Files%+1
Echo.)

set temp=
set fyyyy=
set fmm=
set fdd=

:EXIT

edited by moderator: Removed email address -Razor 2.3


See More: solution how to change the dir to del in the

Report •


#1
December 11, 2009 at 11:12:40
There is only one dir command:

Dir %Force_Delete% "%FileName%"

I guess "dir" changes to "del", but leave the vars intact.

If you can still edit your post, I suggest you disguise the email address so the spambots don't pick it up.


Batch Variable how to


Report •

#2
December 14, 2009 at 01:08:27
I have tried it before, but still didn't work

------------------
Batch File Name: Delete-Files.bat
Code: MS-DOS
OS: Windows XP Professional, SP2
------------------

@echo off
REM 12 December 2009
REM
REM The purpose of this program is to delete files by a user specified Old-Than-x-Day value.
REM
REM The core code (111 lines) was taken off the internet.
REM Credit goes to: Chrispie & Dtech10.
REM Web Site: http://www.computing.net/programmin...
REM
REM All the necessary modifications and additions were made by: Pete Soski
REM [SoskiP@Yahoo.com]
REM
REM This code has been drafted and tested on Windows XP Professional, SP2.
REM Compatibility testing on different OS's will be necessary.
REM
REM Packaged by default, this program will only run a DIR command, not a DEL command.
REM See comments towards the bottom of the code to change into a DEL program.
REM
REM This program can do the following:
REM - Accept a value that purges files by date. Files older then the value are deleted.
REM - Accept a path in which to begin searching
REM - The path can be a network path.
REM - Accept value; namely an extension, allowing wildcards to limit selection
REM - Program will list all deleted files
REM - Program will list all evaluated files
REM - Accept value to enable or disable sub-directory searching.
REM - Accept value to enable or disable Read-Only file deletion.
REM - Program will give the number of files deleted
REM - Program will give the number of files skipped over
REM - Program will give total number of files processed.
REM - Program Start Time will be posted
REM - Program Finish Time will be posted.
REM - The program will also calculate and post elapsed time.
REM

CLS
:HouseKeeping
REM Start Time
REM This will load the current time into 'Start' variables.
REM.
Set Start_Time=%time%
FOR /f "tokens=1-3 delims=:." %%a in ('echo %time%') do (
set Start_hh=%%a
set Start_mm=%%b
set Start_ss=%%c
)
FOR /f "tokens=1-3 delims=: " %%a in ('time /t') do (set Start_Meridan=%%c)
Echo Start Time: %Start_hh%:%Start_mm%:%Start_ss% %Start_Meridan%

Set Delete_Counter=0
Set FChecked_Counter=0
Set Total_Files=0
Set Finish_day=0
SET OLDERTHAN=%1
SET FileDir=%~2
SET EXT=%3
SET Sub_Dir=%4
SET Force_Check=%5
IF NOT DEFINED OLDERTHAN GOTO SYNTAX
IF NOT DEFINED FileDir GOTO SYNTAX
IF NOT DEFINED EXT GOTO SYNTAX
IF NOT DEFINED Force_Check Goto Get_Date
IF DEFINED Force_Check Goto Read_Only
Goto Exit

:Read_Only
IF %Force_Check%==1 set Force_Delete=/F
Goto Get_Date

REM Get Todays Date
:Get_Date
FOR /f "tokens=1-4 delims=/- " %%a in ('date /t') do (
set xx=%%a
set mm=%%b
set dd=%%c
set yyyy=%%d
)

set /A mm=%mm%+0
if %dd%==01 set dd=1
if %dd%==02 set dd=2
if %dd%==03 set dd=3
if %dd%==04 set dd=4
if %dd%==05 set dd=5
if %dd%==06 set dd=6
if %dd%==07 set dd=7
if %dd%==08 set dd=8
if %dd%==09 set dd=9
set /A dd=%dd%+0
set /A dd=%dd% - %OLDERTHAN%
set /A yyyy=%yyyy%+0

:LOOPDATE

if /I %dd% GTR 0 Goto DONE
set /A mm=%mm% - 1
if /I %mm% GTR 0 Goto ADJUSTDAY
set /A mm=12
set /A yyyy=%yyyy% - 1

:ADJUSTDAY
if %mm%==1 Goto SET31
if %mm%==2 Goto LEAPCHK
if %mm%==3 Goto SET31
if %mm%==4 Goto SET30
if %mm%==5 Goto SET31
if %mm%==6 Goto SET30
if %mm%==7 Goto SET31
if %mm%==8 Goto SET31
if %mm%==9 Goto SET30
if %mm%==10 Goto SET31
if %mm%==11 Goto SET30
if %mm%==12 Goto SET31

:SET31
set /A dd=31 + %dd%
Goto LOOPDATE

:SET30
set /A dd=30 + %dd%
Goto LOOPDATE

:LEAPCHK
set /A tt=%yyyy% %% 4
if not %tt%==0 Goto SET28
set /A tt=%yyyy% %% 100
if not %tt%==0 Goto SET29
set /A tt=%yyyy% %% 400
if %tt%==0 Goto SET29

:SET28
set /A dd=28 + %dd%
Goto LOOPDATE

:SET29
set /A dd=29 + %dd%

:DONE
if /i %dd% LSS 10 set dd=0%dd%
if /I %mm% LSS 10 set mm=0%mm%

:Search_Type
IF NOT DEFINED Sub_Dir GOTO No_Sub_Dir
If %Sub_Dir%==0 Goto :No_Sub_Dir
If %Sub_Dir%==1 Goto :Sub_Directory
Else Goto :No_Sub_Dir

:No_Sub_Dir
for %%i in (%FileDir%\%EXT%) do (
set FileName=%%i
call :PROCESSFILE %%~ti)

Goto Print_Results

:Sub_Directory
for /R %FileDir% %%i in (%EXT%) DO (
set FileName=%%i
call :PROCESSFILE %%~ti)

Goto Print_Results

:Print_Results
Echo.
Echo The number of files deleted : %Delete_Counter%
Echo.
Echo The number of files passed over : %FChecked_Counter%
Echo.
Echo The Total number of files processed: %Total_Files%
Echo.
Goto Get_Finish_Time

:Get_Finish_Time
REM This will load the current time into 'Finish' variables.
REM.
FOR /f "tokens=1-3 delims=:." %%a in ('echo %time%') do (
set Finish_hh=%%a
set Finish_mm=%%b
set Finish_ss=%%c
)
FOR /f "tokens=1-3 delims=: " %%a in ('time /t') do (set Finish_Meridan=%%c)
Goto Calculate_Time

:Calculate_Time
REM Calculate the difference in time between Start and Finish times
REM.

IF %Start_ss% GTR %Finish_ss% (
set /A Finish_ss=%Finish_ss%+60
set /A Finish_mm=%Finish_mm%-1
)
set /A Diff_ss=%Finish_ss%-%Start_ss%

IF %Start_mm% GTR %Finish_mm% (
set /A Finish_mm=%Finish_mm%+60
set /A Finish_hh=%Finish_hh%-1
)
set /A Diff_mm=%Finish_mm%-%Start_mm%

IF %Start_hh% GTR %Finish_hh% (
set /A Finish_hh=%Finish_hh%+24
set Finish_day=1
)
set /A Diff_hh=%Finish_hh%-%Start_hh%

REM The follow will adjust for negative time values.
REM.
REM if %Diff_hh% LSS 0 (set /A Diff_hh=%Diff_hh%+23)
REM if %Diff_mm% LSS 0 (set /A Diff_mm=%Diff_mm%+59)
REM if %Diff_ss% LSS 0 (set /A Diff_ss=%Diff_ss%+59)
REM The following will compensate for single digit results.
REM.
if %Diff_hh%==0 set Diff_hh=00
if %Diff_hh%==1 set Diff_hh=01
if %Diff_hh%==2 set Diff_hh=02
if %Diff_hh%==3 set Diff_hh=03
if %Diff_hh%==4 set Diff_hh=04
if %Diff_hh%==5 set Diff_hh=05
if %Diff_hh%==6 set Diff_hh=06
if %Diff_hh%==7 set Diff_hh=07
if %Diff_hh%==8 set Diff_hh=08
if %Diff_hh%==9 set Diff_hh=09
if %Diff_mm%==0 set Diff_mm=00
if %Diff_mm%==1 set Diff_mm=01
if %Diff_mm%==2 set Diff_mm=02
if %Diff_mm%==3 set Diff_mm=03
if %Diff_mm%==4 set Diff_mm=04
if %Diff_mm%==5 set Diff_mm=05
if %Diff_mm%==6 set Diff_mm=06
if %Diff_mm%==7 set Diff_mm=07
if %Diff_mm%==8 set Diff_mm=08
if %Diff_mm%==9 set Diff_mm=09
if %Diff_ss%==0 set Diff_ss=00
if %Diff_ss%==1 set Diff_ss=01
if %Diff_ss%==2 set Diff_ss=02
if %Diff_ss%==3 set Diff_ss=03
if %Diff_ss%==4 set Diff_ss=04
if %Diff_ss%==5 set Diff_ss=05
if %Diff_ss%==6 set Diff_ss=06
if %Diff_ss%==7 set Diff_ss=07
if %Diff_ss%==8 set Diff_ss=08
if %Diff_ss%==9 set Diff_ss=09
Goto Print_Time

:Print_Time
REM This will return the results to the user.
REM.
Set End_Time=%time%
Echo.
Echo The program started at: %Start_Time% %Start_Meridan%
Echo The program ended at : %End_Time% %Finish_Meridan%
Echo hh:mm:ss.mm
Echo.
Echo This is the amount of time elapsed from the
Echo start to the end of the program executing.
Echo.
Echo %Diff_hh%:%Diff_mm%:%Diff_ss%
Echo hh:mm:ss
Echo. Number of Days Elapsed: %Finish_day%

Goto Reset_Variables

:Reset_Variables

REM The following will reset the variables used by this program.
REM A.K.A. cleaning up.
set mm=
set yyyy=
set dd=
set thedate=
set xx=
set tt=
set FileDir=
set FileName=
set ext=
set OlderThan=
set Sub_Dir=
set Delete_Counter=
set Total_Files=
set FChecked_Counter=
set Force_Check=
set Force_Delete=
set Diff_hh=
set Diff_mm=
set Diff_ss=
set Start_hh=
set Start_mm=
set Start_ss=
set Start_Meridan=
set Finish_hh=
set Finish_mm=
set Finish_ss=
set Finish_Meridan=
set mm=
set hh=
set ss=
set Start_Time=
set End_Time=
set Finish_day=
Goto Exit

:SYNTAX
Echo.
Echo USAGE:
Echo Delete-Files.bat [Days] [Dir] [File-Extension] [Sub-Directory Search] [Read_Only_Delete]
Echo Delete-Files x C:\ wildcard.ext 0 or 1 0 or 1
Echo.
Echo Mandatory: "Delete-Files [Days] [Dir] [File-Extension]"
Echo "Delete-Files 180 C:\Temp *.Log"
Echo.
Echo Where:
Echo [Days] = Number
Echo Determines the number of days previous to Today that will be selected.
Echo.
Echo Example: "Delete-Files.bat 5 C:\Temp *.LOG" Deletes all LOG files older than 5 days.
Echo.
Echo [Dir] = Path
Echo "Delete-Files.bat 120 C:\Temp *.LOG" Deletes all LOG files from the
Echo "C:\Temp" directory that are older than 120 days.
Echo.
Echo [File-Extension] = wildcards and extension
Echo This detemined which files or file-types that will be deleted.
Echo.
Echo Wildcards are allowed. [* ?]
Echo Examples: [*.* , *.LOG , ~*.*]
Echo.
Echo Example: "Delete-Files.bat 15 C:\Temp *.LOG"
Echo Example: This will delete all LOG files older than 15 days from C:\Temp
Echo.
Echo [Sub-Directory Search] = 1 or 0
Echo.
Echo Possible values {0 , 1}
Echo A value of "0" or blank, will not search sub-directory for possible files
Echo to delete.
Echo.
Echo A value of "1" and only "1", will search every directory underneath the
Echo the specified directory. If C:\Temp and "1" then C:\Temp and C:\Temp\srbackup\..
Echo will be searched and evaluated for file deletion.
Echo.
Echo Example: "Delete-Files.bat 5 C:\Temp *.LOG 1"
Echo This will search C:\Temp and ALL sub-directories for *.LOG files, older
Echo then 5 days and delete them.
Echo.
Echo Example: "Delete-Files.bat 5 C:\Temp *.LOG"
Echo This will search ONLY C:\Temp for *.LOG files older than 5 days and
Echo delete those that qualify.
Echo.
Echo [Read_Only_Delete] = 1 or 0
Echo WARNING!
Echo The Sub-Directory Search value must be present for this to work.
Echo.
Echo This fifth control-switch will force the deletion of Read-Only files.
Echo Enter a "1" if the forced deletion of Read-Only files is wanted.
Echo Leave the value empty or specify "0" to keep Read-Only untouched.
Echo.
Echo Example: "Delete-Files.bat 120 C:\Temp *.LOG 0 1"
Echo This will delete all LOG files, over 120 days, in C:\Temp, and will
Echo be deleted even if Read-Only. This switch will delete regular and Read-Only files.
Echo.
Echo Example: "Delete-Files.bat 120 C:\Temp *.LOG 0 0"
Echo This will delete all LOG files, over 120 days, in C:\Temp, and
Echo will NOT delete Read-Only files.
Echo.
Echo Example: "Delete-Files.bat 120 C:\Temp *.LOG 1 1"
Echo This will delete all LOG files, over 120 days, in C:\Temp, in all subdirectories of C:\Temp
Echo and will delete files Read-Only and regular.
Echo.

Echo Delete-Files.bat [Days] [Dir] [File-Extension] [Sub-Directory Search] [Read_Only_Delete]
Echo Delete-Files x C:\ wildcard.ext 0 or 1 0 or 1
Echo.
Echo Mandatory: "Delete-Files [Days] [Dir] [File-Extension]"
Echo "Delete-Files 180 C:\Temp *.Log"
Echo.
Echo -- End of help --

GOTO Exit

:PROCESSFILE
set temp=%1
set fyyyy=%temp:~6%

if /I %fyyyy% LSS 100 set fyyyy=20%fyyyy%
if /I %fyyyy% GTR 2069 set fyyyy=19%temp:~6%

set fmm=%temp:~0,2%
set fdd=%temp:~3,2%

:: +*************************************+
:: | This is where the files are deleted |
:: | Change the DIR command to DEL to |
:: | delete. DIR is used for test. |
:: +*************************************+

if /I %yyyy%/%mm%/%dd% GEQ %fyyyy%/%fmm%/%fdd% (
Echo "- The selected file will be deleted."
Echo "%FileName%"
Del %Force_Delete% "%FileName%"
Set /A Delete_Counter=%Delete_Counter%+1
Set /A Total_Files=%Total_Files%+1
Echo.
) Else (
Echo "The selected file does not qualify for deletion."
Echo "%FileName%"
Set /A FChecked_Counter=%FChecked_Counter%+1
Set /A Total_Files=%Total_Files%+1
Echo.)

set temp=
set fyyyy=
set fmm=
set fdd=

:EXIT


Report •

Related Solutions


Ask Question