WatchDirectory Forum
watchDirectory forums >> Plugins >> Copy file to 2 diff folders based on filename

Message started by puddwud on Feb 18th, 2014 at 4:22pm

Title: Copy file to 2 diff folders based on filename
Post by puddwud on Feb 18th, 2014 at 4:22pm

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:


where the filename will have the structure of:


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.


Title: Re: Copy file to 2 diff folders based on filename
Post by Gert on Feb 18th, 2014 at 5:17pm

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.

Title: Re: Copy file to 2 diff folders based on filename
Post by puddwud on 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

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\SomeRamdom File name.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:


…they also need copying to:


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?


Title: Re: Copy file to 2 diff folders based on filename
Post by Gert on Feb 20th, 2014 at 7:22am

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 P1=%F6:~0,1%
IF "%P1%" EQU "0" (
   SET F6=%F6:~1%
   GOTO :RemoveZeroes

Now you can use this script as part of your {dynamic name}, for example:

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:

Title: Re: Copy file to 2 diff folders based on filename
Post by puddwud on 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.


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