Andy Jarrett
Andy Jarrett

Reputation: 873

Zip up 500k + files based on their creation date

I have inherited a folder with 500,000 PDFs (each around 300kb+) and a load of JPGs (each around 100kb+) in there.

I'm on Windows and want to know if or how I can move them into folders based on their creation date, then zip each folder individually (I am using 7zip) all via a batch command.

Upvotes: 0

Views: 164

Answers (1)

Will Ryan
Will Ryan

Reputation: 681

You could do something like this:

set DIRTOZIP="C:/MyPath"
set TEMPDIR="C:/MyTempPath"
set ZIPFILE="C:/MyPath/MyZipFile.zip"
rmdir %TEMPDIR%
mkdir %TEMPDIR%
ROBOCOPY /maxage:3 /minage:3 %DIRTOZIP% %TEMPDIR%
echo Set objArgs = WScript.Arguments > _zipIt.vbs
echo InputFolder = objArgs(0) >> _zipIt.vbs
echo ZipFile = objArgs(1) >> _zipIt.vbs
echo CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" ^& Chr(5) ^& Chr(6) ^& String(18, vbNullChar) >> _zipIt.vbs
echo Set objShell = CreateObject("Shell.Application") >> _zipIt.vbs
echo Set source = objShell.NameSpace(InputFolder).Items >> _zipIt.vbs
echo objShell.NameSpace(ZipFile).CopyHere(source) >> _zipIt.vbs
echo wScript.Sleep 2000 >> _zipIt.vbs
CScript  _zipIt.vbs  %TEMPDIR%  %ZIPFILE%

Note the ROBOCOPY line, the maxage variable is set to 3 and the minage variable is also set to 3, this will copy all files 3 days old into the temp directory and then zip it all up for you.

I haven't tested this script but I've used something similar before.

Upvotes: 1

Related Questions