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
Copy file to 2 diff folders based on filename (Read 4821 times)
puddwud
YaBB Newbies
*
Offline



Posts: 5
UK
Copy file to 2 diff folders based on filename
Feb 18th, 2014 at 4:22pm
 
Hi,

I'm currently evaluating WatchDirectory (which is looking very good so far) but am trying to determine the best way of achieving the following:

Source files (tiffs) sit in the folder structure c:\Monitored Folder\{firstdir}\

files will have two name formats and have to be processed differently depending on this.

If the files DO NOT start with a 6 digit number, then they are just copied to a network volume with a subfolder named the same as the source subfolder - I can see this is easy to do using 'Copy Files' plugin.

If the files DO start with a 6 digit number, then they need to be copied to 2 locations.  The first the same network volume as above and the second is into a folder structure on the K: drive in the format:

K:\FileStore\002001-003000\002456\tif-files-{firstdir}-S\

where the filename will have the structure of:

002456-(twoDigits)-{firstdir}-S_someText.tif

K:\FileStore\ has subfolders numbered in 1000 number ranges, (003001-004000, 004001-005000 etc.)

Where the source file is to be stored will be dependant on the first 6 chars (must be digits) of its filename.

I can see that Multiple SubTasks can help with multiple destination but I currently cannot see a way of determining the correct destination sub-subfolder (i.e. 002001-003000) using dynamic naming tags.  Am I correct in this or am I missing a trick here?

Any help/guidance would be appreciated.

Cheers
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2224
The Netherlands
Re: Copy file to 2 diff folders based on filename
Reply #1 - Feb 18th, 2014 at 5:17pm
 
Hi,

Can you give me a few example "detected" filenames (complete paths) and the resulting "target" filenames, because I am not really sure I understand.

But I think you need to look at the {substring{start,length,text}} dynamic name function. http://www.watchdirectory.net/wdhelp/plugins/dynamicname_functions.html
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
 
puddwud
YaBB Newbies
*
Offline



Posts: 5
UK
Re: Copy file to 2 diff folders based on filename
Reply #2 - Feb 19th, 2014 at 2:26pm
 
Hi Gert,

Thanks for your reply.  I'll try and clarify for you.

Sources files will be of the form

001245-00-ABC-100-S_buy.tif
004567-01-DEF-125-R_sel.tif
SomeRamdom File name.tif
AnotherRamdom File name.tif

They will all be in a series of subfolders of C:\Monitored Folder\ named:

C:\Monitored Folder\ABC-100\
C:\Monitored Folder\DEF-125\
C:\Monitored Folder\GHI-150\

So using the file names above, their paths would/could be in:

C:\Monitored Folder\ABC-100\001245-00-ABC-100-S_buy.tif
C:\Monitored Folder\ABC-100\SomeRamdom File name.tif
C:\Monitored Folder\DEF-125\004567-01-DEF-125-R_sel.tif
C:\Monitored Folder\GHI-150\SomeRamdom File name.tif
C:\Monitored Folder\GHI-150\AnotherRamdom File name.tif

In all cases these files need to be copied to the network volume destinations as follows

\\tfx\ABC-100\001245-00-ABC-100-S_buy.tif
\\tfx\ABC-100\SomeRamdom File name.tif
\\tfx\DEF-125\004567-01-DEF-125-R_sel.tif
\\tfx\GHI-150\SomeRamdom File name.tif
\\tfx\GHI-150\AnotherRamdom File name.tif

In the case of the files that start with 6 digits:

001245-00-ABC-100-S_buy.tif
004567-01-DEF-125-R_sel.tif

…they also need copying to:

K:\FileStore\001001-002000\001245\tif-files-abc-100-S\001245-00-ABC-100-S_buy.ti
f
K:\FileStore\004001-005000\004567\tif-files-def-125-S\004567-01-DEF-125-R_sel.ti
f

Files that do not start with 6 digits need no further processing.

The bit I’m struggling with is working out the second delivery required for the files starting with 6 digits due to the file needed to to end up in a job number folder (first 6 digits of filename) within a subfolder (rangeStart-rangeEnd) in the K:\FileStore\.

I can see how {substring{start,length,text}} can help in extracting the first 6 digits to enable the job folder creation but not the range parent folder. As in how do I deliver 001245-00-ABC-100-S_buy.tif into the job folder beneath K:\FileStore\001001-002000\ whilst 004567-01-DEF-125-R_sel.tif is delivered to the job folder beneath K:\FileStore\004001-005000\?

Hope this clarifies what I need to achieve.  Any ideas?

Cheers
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2224
The Netherlands
Re: Copy file to 2 diff folders based on filename
Reply #3 - Feb 20th, 2014 at 7:22am
 
Hi,

Ok, here is what you can do (you need at least WD 4.7 for this).

Save the script below as getFolder.bat in directory
<WD Install Directory>\Resolvers
(typically C:\Program Files (x86)\WatchDirectory\Resolvers)
Code:
rem get the first 6 digits of the filename
SET F6=%WD_FILE_B:~0,6%
rem remove leading zeroes (otherwise SET will interpret it as an octal number)
Call :RemoveZeroes

rem get the number modulo 1000
SET /A MOD1000=%F6% %% 1000
echo %MOD1000%

rem the destination folder
SET /A FOLDER1=%F6% - %MOD1000% + 1
SET /A FOLDER2=%FOLDER1% + 1000 - 1
rem make sure both names have the correct nr of leading zeroes
SET FOLDER1=000000%FOLDER1%
SET FOLDER1=%FOLDER1:~-6%
SET FOLDER2=000000%FOLDER2%
SET FOLDER2=%FOLDER2:~-6%
echo %FOLDER1%-%FOLDER2% > "%WD_FILTERRESULT%"
GOTO :EOF


:RemoveZeroes
SET P1=%F6:~0,1%
IF "%P1%" EQU "0" (
   SET F6=%F6:~1%
   GOTO :RemoveZeroes
)
GOTO :EOF
 



Now you can use this script as part of your {dynamic name}, for example:
K:\FileStore\{code{getFolder.bat,}}\{left{6,%WD_FILE_N%}}\.......

I just noticed that using bat files for dynamic naming is not documented yet, that will be fixed in a future release. For now you can look at the sample here: http://www.watchdirectory.net/cgi-bin/yabb25/YaBB.pl?num=1352102554



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
 
puddwud
YaBB Newbies
*
Offline



Posts: 5
UK
Re: Copy file to 2 diff folders based on filename
Reply #4 - Feb 21st, 2014 at 9:25am
 
Hi Gert,

Thank you very much for this, much appreciated. This ability to apply custom processing through dynamic naming is what I was missing.

Cheers,
Back to top
 
 
IP Logged
 
Page Index Toggle Pages: 1