Solved Copy month end zip files only to another location

January 19, 2016 at 00:58:51
Specs: Windows 7

Currently, I have a batch script which keeps the daily zip file backups for the last 60 days.
forfiles /p "D:\Archive" /s /m *.zip /c "cmd /c Del @path" /d -60

My next step is to copy the month end zip file backups only from "Archive" folder into another folder (Eg; "Monthly"). This script can be executed daily to check if there's any zip files created on month end.
This "Monthly" folder will only store zip files which is created on 31/1/2016, 29/2/2016, etc....

Please advise if this is possible. Thanks.

See More: Copy month end zip files only to another location

Report •

January 19, 2016 at 23:14:36
"Please advise if this is possible. Thanks".

Yes it's possible.

Report •

January 20, 2016 at 05:24:56
Pls show some sample scripts on how to handle that?

Report •

January 20, 2016 at 10:16:43
✔ Best Answer
Task scheduler has an option for "run on last day of month":

@echo off & setlocal
:: this just creates the task, it does not need to be a batch
schtasks /create /tn embakup /tr "c:\aaa\bbb\eombak.bat" /sc MONTHLY /M * /mo LASTDAY

::---- eombak.bat EXAMPLE ONLY - the details and logistics are probably not going to work as given,
:: you'll have to "tweak" or customize it yourself. This one just goes backward grabbing whatever date
:: is at the top, until the date changes, then it quits
@echo off & setlocal enabledelayedexpansion
set prev=
:: where to copy the files from
set source=c:\xxx\yyy
:: and to
set dest=d:\aaa\bbb
::---- begin loop
for /f "tokens=*" %%a in ('dir /b /s /o-d %source%\*.zip') do (
if not defined prev (
call :aa %%~ta
set prev=!cur!
call :aa %%~ta
::----- loop exits here unless all files have the same date
if !cur! neq !prev! goto :eof
:: you can use MOVE instead of COPY in foll. line
copy %%a %dest%\%%~nxa
goto :eof

set cur=%1
::==== end script - NOT TESTED.

message edited by nbrane

Report •

Related Solutions

Ask Question