WatchDirectory home page
WatchDirectory Startseite (Deutsche Version)
Site WatchDirectory (Français)
  Welcome, Guest. Please Login or Register
YaBB - Yet another Bulletin Board
   
  HomeHelpSearchLoginRegister  
 
Page Index Toggle Pages: 1
Zipping files with same filename but different ext (Read 1905 times)
Ade
YaBB Newbies
*
Offline



Posts: 4
Zipping files with same filename but different ext
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
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2224
The Netherlands
Re: Zipping files with same filename but different ext
Reply #1 - 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

 

Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
Ade
YaBB Newbies
*
Offline



Posts: 4
Re: Zipping files with same filename but different ext
Reply #2 - Aug 11th, 2014 at 1:37pm
 
Thanks Gert - I'll give that a try!
Back to top
 
 
IP Logged
 
Page Index Toggle Pages: 1