WatchDirectory Forum
http://www.watchdirectory.net/cgi-bin/yabb25/YaBB.pl
watchDirectory forums >> How to... >> Best way to...
http://www.watchdirectory.net/cgi-bin/yabb25/YaBB.pl?num=1128476918

Message started by ScottRoberts on Oct 5th, 2005 at 3:48am

Title: Best way to...
Post by ScottRoberts on Oct 5th, 2005 at 3:48am
The following files arrive in my monitored directory at the same time:

audio1 10am.mp3
audio1 11am.mp3
audio2 10am.mp3
.
.
.audio440 10am.mp3

I need to move and rename as follows:

audio1 10am.mp3 becomes d:\audio1\00410201.mp3
audio1 11am.mp3 becomes d:\audio1\00410301.mp3
audio2 10am.mp3 becomes d:\audio2\AUD10010.mp3
.
.
.
audio440 10am.mp3 becomes d:\audio440\08001001.mp3

(the point being, as many as 400-500 files could concievably arrive at the same time, and for each root file name (audio1, audio2, etc) the renaming convention is different, and the file is moved to a subdirectory named the same as the base file name).

I'd like to create a cross reference file for each base name. For instance, audio1.xref might contain these lines:

audio1 9am.mp3 (tab)0410101.mp3
audio1 10am.mp3 (tab)0410201.mp3
...etc

Am I going to have to cobble together my own batch files/shell scripts (I can do a lot more with grep & other unix tools than a batch file ever dreamed of, and I already have a virtual unix environment installed), or is an add-in possible that would allow one to set up a cross-reference file like I described above...or even better, could the file move routine be expanded to include file-specific renaming? (In my case, we could be talking about well over 1,000 file renaming rules)

What is your suggestion as to the best way to accomplish this, using the least resources?

Title: Re: Best way to...
Post by Gert on Oct 5th, 2005 at 7:01am
Hi,

This is best handled using a .bat script - you are right .bat is not an extremely powerfull language, but this should be possible.

cross refference file
Please see the GdPUtil description here: (http://www.watchdirectory.net/watchDir/GdPUtil.html.
Use the -initobat switch to transform an .ini file to a .bat. Your audio1.ini would look like

Code (]
[naming):


audio1 9am.mp3=0410101.mp3
audio1 10am.mp3=0410201.mp3

and after calling

Code (]
GdPUtil -initobat c:\xref\audio1.ini c:\xref\audio1.bat
[/code):


You can do things like
[code]
Call c:\xref\audio1.bat "namng" "audio1 9am.mp3"
Echo the value for 9am is %RESULT%


You would only need to call the -initobat once (after creating/changing the xref files).

So, your .bat file would be something like:
[code]
echo the new file is %WD_FILE%
rem get the first 6 or 7 chars of the filename
if "%WD_FILE_N:~6:1%" equ " " (
 Set XRF=%WD_FILE_N:~0,6%
) else (
 Set XRF=%WD_FILE_N:~0,7%
)
Call c:\xref\%XRF%.bat naming "%WD_FILE_N%"
move "%WD_FILE%" "D:\%XRF%\%RESULT%"
[/code]
To see an overview of all environment vars you have inside a watchDirectory script, see http://www.watchdirectory.net/wdhelp/plugins/wdopAutoRunBatEnv.html.

Hope this helps,
Gert

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