Page 1 of 1

Archive files based on the file date.

Posted: 05 Oct 2010 23:42
by justinnen
Hi,

I have a folder where number of pdf files get accumulated daily.
I need to archive those files on based on the month.
The date or the month is not mentioned anywhere in the file name. The only way to get, is the date on which it is put into the system. The file names would be random ..say -
Microsoft.Adobe Acrobat 7.0 Document
IBM.Adobe Acrobat 7.0 Document
Apple.Adobe Acrobat 7.0 Document

Please help me.
Plese drop a mail to justinnen@gmail.com

Re: Archive files based on the file date.

Posted: 06 Oct 2010 02:43
by amel27
sample for 7z:

dir - folder with files
arc - path & prefix of archive name (month & year added)

Code: Select all

@echo off
SETLOCAL EnableDelayedExpansion

set dir=C:\FILES
set arc=C:\ARCH\TEST_

for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('"echo.|date"') do set /a %%a=1,%%b=2,%%c=3

pushd "%dir%"& for /f "tokens=1-3,5* delims=/.- " %%^1 in (
'dir /tc/4/a-d/-c "%dir%"^|findstr /brc:"[0-9][0-9]"'
) do echo 7z a "%arc%%%%yy%-%%%mm%" "%%5"

!!! script generate archive name by create date, NOT by modify date !!!