I am having one requirement as below :
I want to create a batch job which will pickup only last months text file from folder. To pick all files from 1st Day of previous month to last day of previous month which are created in previous month.
Lets say my batch job is running on 8th of every month, so when it will run on 8th of month, it should pickup all text files from 1st Oct to 31st Oct.
Ex : If batch job runs on 8th Dec 2016, it should pick up all files if Nov month from folder based on the files created in Nov.
Any help would be greatly appreciated.
To pick text files from previous month
Moderator: DosItHelp
Re: To pick text files from previous month
You have not specified what date you are referring to.
1) Is there a date in the file name?
2) Do we use the file systems create date?
3) Do we use the file systems modified date?
1) Is there a date in the file name?
2) Do we use the file systems create date?
3) Do we use the file systems modified date?
-
- Posts: 3
- Joined: 23 Nov 2016 21:39
Re: To pick text files from previous month
We will refer only creation date of file. There is no Date mentioned in text files. We will pick up files based on creation date only i.e files created in last month.
Re: To pick text files from previous month
Then that becomes region dependent. Need to know how your computer displays the date in the DIR command.
-
- Posts: 3
- Joined: 23 Nov 2016 21:39
Re: To pick text files from previous month
It displays the date in MM/DD/YYYY format.
-
- Posts: 239
- Joined: 04 Mar 2014 11:14
- Location: germany
Re: To pick text files from previous month
with this batch you can specify from which month a backup should occur.
at least one month must be given.
the annual backup is as possible as one of all three months.
or whatever they would like to set.
Phil
at least one month must be given.
the annual backup is as possible as one of all three months.
or whatever they would like to set.
Code: Select all
@echo off
setlocal
:: rem Starttime
@robocopy /L |findstr /rc:"[0-9]:[0-9]"
:: Settings Month
rem - how many months ago should the backup be begun?
set /a AgoMonth=1
rem - how many months have to go in the backup
set /a MonthGoBackup=1
:Timestamp
rem robocopy /L "\.. Timestamp ..\\" .
for /f "eol=D tokens=1-6 delims=/: " %%T in (' robocopy /L /njh "\|" .^|find "123" ') do (
set "TS=%%T%%U%%V-%%W%%X%%Y"
set "TSDATE=%%T%%U%%V"
set /a YY=%%T , MM=100%%U %%100 , TT=100%%V %%100
)
:: end Timestamp
:calculateMonthRC /maxage /minage
set /a M.all =YY *12 +MM -1 -AgoMonth
set /a BU.begin =M.all /12 *100 +M.all %%12 +1
set /a BU.end =(M.all +MonthGoBackup) /12 *100 +(M.all +MonthGoBackup) %%12 +1
set /a n.BU.end =(M.all -1 +MonthGoBackup) /12 *100 +(M.all -1 +MonthGoBackup) %%12 +1
if %n.BU.end% == %BU.begin% (set "s.BU.end=") else set "s.BU.end=- %n.BU.end%"
set /a RCdateMax =BU.begin *100 +1
set /a RCdateMin =BU.end *100 +1
echo you want to backup: %BU.begin% %s.BU.end%
:: Settings for Backup please
robocopy /L /S /maxage:%RCdateMax% /minage:%RCdateMin% . "D:\.. Backupfolder ..\\" *.txt /ndL /fp /Xj /nc /ns /np /TS /R:0
:: end
pause
Phil