WatchDirectory Forum
http://www.watchdirectory.net/cgi-bin/yabb25/YaBB.pl
watchDirectory forums >> How to... >> Zipping files with same filename but different ext
http://www.watchdirectory.net/cgi-bin/yabb25/YaBB.pl?num=1407423901

Message started by Ade on Aug 7th, 2014 at 5:05pm

Title: Zipping files with same filename but different ext
Post by Ade on Aug 7th, 2014 at 5:05pm
Dear All,
What is the best way to accomplish the following? I have a single directory with multiple files in it e.g.:
file1.txt
file1.pdf
file2.txt
file2.pdf

I would like to create file1.zip containing file1.txt and file1.pdf, and file2.zip with file2.txt and file2.pdf etc. I need to check that both file1.txt and file1.pdf exist before zipping? The final file1.zip file can be placed in a different directory if necessary.
Many thanks,
Ade

Title: Re: Zipping files with same filename but different ext
Post by Gert on Aug 8th, 2014 at 6:02am
Hi,

This should be possible using the "run a batch file" plugin, see http://www.watchdirectory.net/wdhelp/plugins/wdopAutoRunBat.html

Below you see an example batch file (save it as C:\Bin\autorar.bat) that uses the free WinRar "rar.exe" to create a rar file. I think it also supports zip format.


Code (]rem zips [filename):
.txt and [filename].pdf when both are found

SET TARGETDIR=C:\PlaceArchivesHere
SET MAXWAITTIME=30
SET RAR=C:\Program Files\WinRar\rar.exe

rem we should only be called for txt files and ignore other filetypes
IF /I "%WD_FILE_E%" NEQ "TXT" GOTO :EOF

rem now we wait until the corresponding pdf is available
SET PDF=%WD_FILE_D%%WD_FILE_B%.pdf
Call :WaitForPDF
IF "%RESULT%" EQU "NOK" GOTO :EOF

rem now archive both txt and pdf
"%RAR%" a "%TARGETDIR%\%WD_FILE_B%.rar" "%WD_FILE%" "%PDF%"

rem and we are done
GOTO :EOF



:WaitForPDF
SET GDPU=%WD_INSTDIR%\gdputil.exe
SET RESULT=NOK

:WaitForPDF_again
IF %MAXWAITTIME% LEQ 0 GOTO :EOF
SET /A MAXWAITTIME=%MAXWAITTIME% - 1
"%GDPU%" -sleep 1
IF NOT EXIST "%PDF%" GOTO :WaitForPDF_again
SET RESULT=OK
GOTO :EOF

Title: Re: Zipping files with same filename but different ext
Post by Ade on Aug 11th, 2014 at 1:37pm
Thanks Gert - I'll give that a try!

WatchDirectory Forum » Powered by YaBB 2.5.2!
YaBB Forum Software © 2000-2017. All Rights Reserved.