Computing.Net > Forums > Windows XP > Delete privious month backup folder

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Delete privious month backup folder

Reply to Message Icon

Name: hrshelke
Date: August 12, 2009 at 10:43:40 Pacific
OS: Windows XP
Product: Hewlett-packard / Compaq nc8230
Subcategory: General
Comment:

Hi,

I have backup folder
Backup_2009_15_07 ,Backup_2009_16_07
and Backup_2009_10_08. I want to know batch file commands which will deletes all previous month back up folders like Backup_2009_15_07 ,Backup_2009_16_07 except Backup_2009_10_08 from folder C:\Batch\ARCHIVE\FINAL

Please let me know the code



Sponsored Link
Ads by Google

Response Number 1
Name: dtech10
Date: August 12, 2009 at 12:25:58 Pacific
Reply:

Hi

In order to help you we need to know your date format in order to idenify the current month.
Type this at the Dos prompt and post it back.

echo %Date%


0

Response Number 2
Name: hrshelke
Date: August 12, 2009 at 13:23:01 Pacific
Reply:

C:\>date
The current date is: Wed 08/12/2009
Enter the new date: (mm-dd-yy)

I am creating backup folder by folloing code
set Day=%Date:~7,2%
set Mth=%Date:~4,2%
set Yr=%Date:~10,4%

c:\Batch\ARCHIVE\FINAL\BACK_%Yr%_%Mth%_%Day%


0

Response Number 3
Name: OtheHill
Date: August 12, 2009 at 13:25:02 Pacific
Reply:

Not to throw water on your fire but if you only have a few why bother? Just manually delete. Do you verify your backups?


0

Response Number 4
Name: hrshelke
Date: August 12, 2009 at 13:28:43 Pacific
Reply:

The above is example with few folders. I am going to have lots of folders . Just i want code which deletes previous month folder and keep this month under C:\Batch\ARCHIVE\FINAL.


0

Response Number 5
Name: dtech10
Date: August 12, 2009 at 14:34:19 Pacific
Reply:

Hi Hrshelke

Delete the /s if you don't want confirmation, but it's best to leave it for testing.
I take it that there only last months backup files in the %Dir% directory.

@echo off
set Mth=%Date:~4,2%
set DIR=C:\Batch\ARCHIVE\FINAL
for /f "tokens=1-4 delims=_" %%a in ('dir /b /ad %Dir%') do (
if %%d LSS %Mth% (rd /s %Dir%\%%a_%%b_%%c_%%d)
)


0

Related Posts

See More



Response Number 6
Name: hrshelke
Date: August 12, 2009 at 14:48:55 Pacific
Reply:

Thanks dtech10.

The code is working really fine.


0

Response Number 7
Name: dtech10
Date: August 13, 2009 at 07:57:03 Pacific
Reply:

Hi Hrshelke

Forgot to cater for year end.

@echo off
set Mth=%Date:~3,2%
set DIR=g:\@Temp\BATCH\Batch\ARCHIVE\FINAL
for /f "tokens=1-4 delims=_" %%a in ('dir /b /ad %Dir%') do (
if %Mth% EQU 01 (if %%d EQU 12 (rd /s %Dir%\%%a_%%b_%%c_12))
if %%d LSS %Mth% (rd /s %Dir%\%%a_%%b_%%c_%%d)
)


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows XP Forum Home


Sponsored links

Ads by Google


Results for: Delete privious month backup folder

removing old backup www.computing.net/answers/windows-xp/removing-old-backup/147584.html

Deleting weird NT Uninstall folders www.computing.net/answers/windows-xp/deleting-weird-nt-uninstall-folders/144693.html

Cant delete or edit a folder www.computing.net/answers/windows-xp/cant-delete-or-edit-a-folder/125497.html