Archive files based on the file date.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
justinnen
Posts: 1
Joined: 05 Oct 2010 23:29

Archive files based on the file date.

#1 Post by justinnen » 05 Oct 2010 23:42

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

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: Archive files based on the file date.

#2 Post by amel27 » 06 Oct 2010 02:43

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 !!!

Post Reply