anub13
anub13

Reputation: 69

7zip current date with source folder on other path dir

I am trying to zip files with only lastest file modified using 7z, I've take a look at this https://superuser.com/questions/206817/7-zip-cmd-add-current-date-to-archive-and-include-only-the-last-modified-folder

and this

Use 7zip to include files with *current date* only

but they are not in different dir which I have trouble with, currently my command code is like this

@ECHO ON

SET SourceDir=H:\spiral\kmart\inbox
SET DestDir= C:\TCD


CD \TCD
7z.exe a -tzip C:\TCD\KMartInboxXML.zip-i!^C:\TCD\%DATE:~4,2%-%DATE:~7,2%-%DATE:~10,4%.xml "H:\spiral\kmart\inbox\*"


SET DestDir= C:\TCD
pause

EXIT 

and I got this error(see pict)

error1

I know I used wrong dir because wrong command and actually I have tried different command line using forfiles also, I am lost. Any help is very appreciated.

EDIT:

Missing explanation.

Upvotes: 0

Views: 1616

Answers (2)

Compo
Compo

Reputation: 38642

Now you have found a fix for your 7z.exe command, change the rest of the script to:

@ECHO OFF

SET "SourceDir=H:\spiral\kmart\inbox"
SET "ZipName=files_kmartinbox.zip"
SET "DestDir=C:\TCD"
SET "now=%date:~12,2%%date:~7,2%%date:~4,2%"

CD /D "%DestDir%"
7z.exe a "%ZipName%" -r "%SourceDir%\*%now%*" 

Also note that if 7z.exe isn't in %PATH% or %DestDir% you would have to provide it's full or relative path too.

Upvotes: 1

anub13
anub13

Reputation: 69

Got help from my friend, figure it out by altering zip command on the source folder. Because the file is using date, I use variable to find them... format name file is 290427-SHIPMENT-1704180803.xml

So I describe the variable as this

SET now=%date:~12,2%%date:~7,2%%date:~4,2%

will result:

170418

so, any file with file name 170418(that is today) will get zipped, place them in the variable in zip source folder.

Here is the complete code

@ECHO ON


SET SourceDir=H:\spiral\kmart\inbox
SET DestDir= C:\TCD
SET now=%date:~12,2%%date:~7,2%%date:~4,2%


C:
CD \TCD
7z.exe a files_kmartinbox.zip -r "H:\spiral\kmart\inbox\*%now%*" 


SET DestDir= C:\TCD

I hope this is helping people with similliar same problem. Cheers.

Upvotes: 1

Related Questions