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
How to create a .txt file for each newly added TIF (Read 5788 times)
Chris_Quan
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 9
How to create a .txt file for each newly added TIF
Oct 17th, 2004 at 11:04pm
 
Is there a way to create a .txt file for each of the newly added TIF files using the same name? For example, if test12345.tif is added to any of the folder or its sub-folder, a file call test12345.txt should be created in the same folder.

The test12345.txt should be a duplicate of a text file called template.txt. Each of the folders will have its own (unique) template.txt file.

Is this possible?

Thanks.

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



Posts: 2225
The Netherlands
Re: How to create a .txt file for each newly added
Reply #1 - Oct 17th, 2004 at 11:40pm
 
Hello Chris,

Yes, that is possible. Please try the following as your .bat file:
Code:
@echo off
rem only process new files
if "%WD_REASON%" NEQ "FILENEW" GOTO :QUIT
rem only process TIF files
if "%WD_FILE_E%" NEQ "TIF" GOTO :QUIT
rem check if the template.txt file is available
if not exist "%WD_FILE_D%\template.txt" GOTO :NoTemplate

COPY "%WD_FILE_D%\template.txt" "%WD_FILE_D%\%WD_FILE_B%.TXT"
rem the above COPY statement will trigger watchDirectory
rem for a new FILENEW event. Because of line 5 above this won't
rem cause troubles (we only process TIF files)
GOTO :QUIT

:NoTemplate
rem
rem no template.txt file found in the directory of this
rem new .TIF file...
rem You could use a default template file here....
rem for this example, we just ignore this file
rem
GOTO :QUIT

:QUIT
  



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


I love YaBB 1G - SP1!

Posts: 9
Re: How to create a .txt file for each newly added
Reply #2 - Oct 18th, 2004 at 12:25am
 
Hi,

It almost works! It does not copy the template.txt to newfile.txt??

Here is the output.

Executing F:\Program Files\GdP Software\WatchDirectory\tcopy.bat DIRCHNG "J:\IYPH\test5"
Executing F:\Program Files\GdP Software\WatchDirectory\tcopy.bat FILENEW "J:\IYPH\test5" "J:\IYPH\test5\test5\
0939LPae.tif"
Executing F:\Program Files\GdP Software\WatchDirectory\tcopy.bat FILENEW "J:\IYPH\test5" "J:\IYPH\test5\test5\
0939LPam.tif"
Executing F:\Program Files\GdP Software\WatchDirectory\tcopy.bat FILENEW "J:\IYPH\test5" "J:\IYPH\test5\test5\
0939LPav.tif"
Executing F:\Program Files\GdP Software\WatchDirectory\tcopy.bat FILENEW "J:\IYPH\test5" "J:\IYPH\test5\test5\
0939LPac.tif"
Executing F:\Program Files\GdP Software\WatchDirectory\tcopy.bat FILENEW "J:\IYPH\test5" "J:\IYPH\test5\test5\
0939LPar.tif"

Any ideas?

Thanks.

Chris
Back to top
 
 
IP Logged
 
Chris_Quan
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 9
Re: How to create a .txt file for each newly added
Reply #3 - Oct 18th, 2004 at 12:38am
 
Never mind! It works! It's beautiful!

Thanks. Now I can go to bed   Smiley

Chris

P.S. Is it possible to make it watch for any newly added files, copy them to a new folder AND ONLY duplicate the template.txt for .TIF files.
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2225
The Netherlands
Re: How to create a .txt file for each newly added
Reply #4 - Oct 18th, 2004 at 12:39am
 
I just tried it on my computer, and it works perfectly.

Note that the template.txt file should be in the same directory as the new TIF file (like you said it would be), otherwise nothing happens.

Perhaps, just to be sure you should temporarily change the .bat file to this:
Code:
 rem @echo off
rem only process new files
if "%WD_REASON%" NEQ "FILENEW" GOTO :QUIT
rem only process TIF files
if "%WD_FILE_E%" NEQ "TIF" GOTO :QUIT
rem check if the template.txt file is available
if not exist "%WD_FILE_D%\template.txt" GOTO :NoTemplate

COPY "%WD_FILE_D%\template.txt" "%WD_FILE_D%\%WD_FILE_B%.TXT"
rem the above COPY statement will trigger watchDirectory
rem for a new FILENEW event. Because of line 5 above this won't
rem cause troubles (we only process TIF files)
GOTO :QUIT

:NoTemplate
rem
rem no template.txt file found in the directory of this
rem new .TIF file...
rem You could use a default template file here....
rem for this example, we just ignore this file
rem
GOTO :QUIT

:QUIT
 pause
 


(so you REM the first line, and add a PAUSE statement at the end).

This will cause the .bat file to echo everything it is doing to the screen, and wait for you press a key before it quits.

The .bat file window will be minimized to your taskbar, so you will have to click it before you see any output.

Also, do not run it with the "hide command window" switch (you can not press a key then).

I am curious what output you get...

Gert
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
 
Gert
YaBB Administrator
*****
Offline



Posts: 2225
The Netherlands
Re: How to create a .txt file for each newly added
Reply #5 - Oct 18th, 2004 at 12:50am
 
Quote:
Never mind! It works! It's beautiful!

We were typing our responses in a beautiful synch...
Perhaps a new Olympic sport next time: SynchroTyping. (Yes, mother -- I do excersise! Wink )
Quote:
P.S. Is it possible to make it watch for any newly added files, copy them to a new folder AND ONLY duplicate the template.txt for .TIF files.


Yup, no problem.
- should all files (also TIF and its .TXT file) be copied to a new folder
- should this new folder already exist, or should it be created by the .bat file.
- naming of this new folder...
- sure you want to copy? don't you want to move???

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


I love YaBB 1G - SP1!

Posts: 9
Re: How to create a .txt file for each newly added
Reply #6 - Oct 18th, 2004 at 1:05am
 
I will create the new folder structure to be the same as the originals. This is so that I can add template.txt to be unique for each of the folders and its sub-folders.

Then, I will copy files into the originals (using automation) so that WD will copy everything plus duplicating the templates in the destination. After that, the original folders will be modified manually by the webmaster.

At the destination folders, WD will duplicate the template.txt for each of the newly added TIF files.

So if WD could

1) Watch the original folders for any newly added files, copy them all to the destination folders in 2)

2) Watch for any newly added TIF files in the destination folders and its sub-folders (each of them will have template.txt) .  Duplicate the template.txt for each TIF files.

How do I do this?  Thanks again. WD saves my days!

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



Posts: 2225
The Netherlands
Re: How to create a .txt file for each newly added
Reply #7 - Oct 18th, 2004 at 4:16pm
 
Chris,

The .bat file below should do the trick.

Code:
@echo off
rem only process new files
if "%WD_REASON%" NEQ "FILENEW" GOTO :QUIT

rem
rem The base directory where you want all new files
rem to be copied to.
rem Below this directory, there should be the same
rem folder structure as the directory that WD is
rem monitoring. The folders below can also contain
rem template.txt files for tif files that arrive here.
SET TARGETDIR=C:\Target

rem
rem the folder to receive this new file is:
rem   %TARGETDIR% + %WD_RELDIR%
rem WD_RELDIR contains the 'relative' directory of the new
rem file. If you are monitoring C:\Monitor and the file
rem C:\Monitor\Sub1\Sub2\NewFile.tif arrives, WD_RELDIR
rem will be set to Sub1\Sub2
rem
IF "%WD_RELDIR%" NEQ "" SET TARGETDIR=%TARGETDIR%\%WD_RELDIR%

rem
rem just to be sure... create the target directory
rem
MKDIR "%TARGETDIR%"

rem
rem copy the new file to the target directory
rem
COPY "%WD_FILE%" "%TARGETDIR%"

rem
rem if this is NOT a tif file, we are done
rem
IF "%WD_FILE_E%" NEQ "TIF" GOTO :QUIT

rem
rem if the target folder does not contain a template.txt file
rem we are done
IF NOT EXIST "%TARGETDIR%\template.txt" GOTO :NoTemplate

rem
rem copy the template
rem
COPY "%TARGETDIR%\template.txt" "%TARGETDIR%\%WD_FILE_B%.TXT"

GOTO :QUIT

:NoTemplate
rem
rem no template.txt file found in the directory of this
rem new .TIF file...
rem You could use a default template file here....
rem for this example, we just ignore this file
rem
GOTO :QUIT

:QUIT
 



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


I love YaBB 1G - SP1!

Posts: 9
Re: How to create a .txt file for each newly added
Reply #8 - Oct 19th, 2004 at 12:52am
 
Thank you very much. I will test it tonight.. I will read the manual a bit to make sure I use it right

Chris
Back to top
 
 
IP Logged
 
Page Index Toggle Pages: 1