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 When One Is Deleted (Read 5788 times)
crazyguy85
YaBB Newbies
*
Offline



Posts: 5
Copy File When One Is Deleted
Apr 4th, 2013 at 7:18pm
 
Hello all, I was wondering if somebody could assist me with my dilemma!

I thing watchDirectory is what I need to do this but don't seem to be able to set it up. I will try to explain as best I can.

I have 2 folders, SOURCE and TARGET. I want to be able to put files into the source folder that will be named xxxx1, xxxx2, xxxx3 etc. I want to auto copy them in numerical order so only one exists in the TARGET directory at a time, then when I delete that file, the next file gets copied in.

So for example xxxx1 will be in the TARGET folder. When I delete it, xxxx2 will be copied across from the source folder, then when I delete that xxxx3 comes across and so on.

I'm not sure if this is possible, as watchDirectory says it can't monitor the folder that files will be auto copied to.

If someone can help with this I would be eternally in your debt!

Many thanks

crazyguy



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



Posts: 2239
The Netherlands
Re: Copy File When One Is Deleted
Reply #1 - Apr 5th, 2013 at 9:01am
 
Hello CrazyGuy,

Can you try to explain a little better with REAL FILENAMES, showing each step you want automated?

WD doesn't have a normal task for what you want to do, but using the "run a .bat file" task it should be possible to automate anything.
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
 
crazyguy85
YaBB Newbies
*
Offline



Posts: 5
Re: Copy File When One Is Deleted
Reply #2 - Apr 5th, 2013 at 9:18am
 
Hi Gert, thanks for your reply.

I work at a robotics company. The robots can only hold a certain amount of files in memory at a time but they have access to a hard drive where files can be stored.

I need a fast way of running a file on the robot, then deleting that file and having the next one auto copy in to the working folder. Filenames can be anything, but as an example I'll use rough1, rough2, rough3.

We machine a piece of polystyrene using rough1. I then delete rough1 and would usually have to go browsing through the file system, then copy and paste rough2. It is a long process when there are lots of files that need running. We would only ever use each file once, then they get deleted. So I would run rough1, then rough2, then rough3.

I hope this clears things up, and again thanks for any help!

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



Posts: 2239
The Netherlands
Re: Copy File When One Is Deleted
Reply #3 - Apr 5th, 2013 at 9:26am
 
nope that doesn't help Wink

I need you to tell me:
What folder should be monitored (C:\Robot ?), also sub-directories???
A sample filename that is created (C:\Robot\rough1) and what should be done with it (moved to C:\Work\rough1 ?)

I think I understand that when "C:\Work\rough1" is deleted you want the next file (C:\Robot\rough2) to be moved to C:\Work\rough2???

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



Posts: 5
Re: Copy File When One Is Deleted
Reply #4 - Apr 5th, 2013 at 9:40am
 
Sorry Gert!

The place storing the files TO BE LOADED is the root of a USB stick (E:) so that would be where they are getting copied from. The filenames would be changing each day, rough is just an example. The folder that the robot works from is C:\roboter\KRC\.

I somehow forgot the following: the file types are .src and .dat. Each file has a .src and a matching .dat. so rough1.src and rough1.dat etc.

I apologise if my replies are rushed and poorly explained, but I appreciate your help!!

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



Posts: 2239
The Netherlands
Re: Copy File When One Is Deleted
Reply #5 - Apr 5th, 2013 at 10:05am
 
Sigh. I really do not have time to guess every little detail, please try to tell me step-by-step what should happen and include FULL filenames (E:\rough1.src) so I know what to do. Please carefully review what I write below because I am about to give up.

This is what I understand so far

1. You plug in an USB stick (drive E: )
2. You want the ?????1.src and ??????1.dat files copied to C:\roboter\KRC
3. When those files (?????1.src / .dat) are deleted from C:\roboter\KRC, the next set (?????2.src / .dat) should be copied to C:\Roboter\KRC
4. When those files (?????2.src / .dat) are deleted from C:\roboter\KRC, the next set (?????3.src / .dat) should be copied to C:\Roboter\KRC
5.....
99. When those files (?????97.src / .dat) are deleted from C:\roboter\KRC, the next set (?????98.src / .dat) should be copied to C:\Roboter\KRC

Is the above 100% correct?

What is the typical range of numbers (rough1.src, rough2.src....... rough9939393933.src)?
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
 
crazyguy85
YaBB Newbies
*
Offline



Posts: 5
Re: Copy File When One Is Deleted
Reply #6 - Apr 5th, 2013 at 11:47am
 
I apologise for any confusion/frustration, I assumed I had explained myself enough!

File names would be E:\rough1.src and rough1.dat. Typical range of numbers I would say would never go above 20. You can not change the robots working folder, which is C:\roboter\KRC\. This is the only folder the robot can run a program from. If I have to copy the first file into this folder manually e.g E:\rough1.src and E:\rough1.dat to C:\roboter\krc\ then that is ok.

1. That is correct
2. That is correct
3. That is correct
4. That is correct

When all the files have been used up, we would start from scratch the next day, so would put a USB stick in again with a fresh bunch of files with the same file names e.g rough1, rough2 etc.

I don't know what else to explain, I hope this is everything.

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



Posts: 2239
The Netherlands
Re: Copy File When One Is Deleted
Reply #7 - Apr 5th, 2013 at 12:39pm
 
I think I have everything I need.

Your remark

> If I have to copy the first file into this folder manually e.g E:\rough1.src and E:\rough1.dat to C:\roboter\krc\ then that is ok.

This really helps. This was the most difficult for me to find out. If you can do that yourself (copying the "1" files), it is a lot easier.

I will write a bat script for you that you can use with the "Run a .bat file" task ( http://www.watchdirectory.net/wdhelp/plugins/wdopAutoRunBat.html ), you let this task monitor C:\Roboter\KRC and let the task start the .bat file when it detects a deleted *.src (or *.dat, but not both) file.
The script will get the base-name from the deleted file (rough123.src -> rough)
The script will get the current "number" from the deleted file (rough123.src -> 123)
The script adds 1 to this number (124)
The script checks if E:\<base name><number>.src (E:\rough124.src) exists and if it does, copies it and its corresponding .dat file to C:\Roboter\KRC

Questions....
Those numbers (the 123 above) appended to the base name (rough), are they always like that (1,2,3,....,13,14,15,....,198,199,...) or do they have leading zeroes (001,002,003,004....,017,018,...)?
I assume their will never be any "holes" in this numbering (1,2,3,5,8,13), correct?
The base name ("rough" in our example), is there anything you can tell me about it? For example, is the base-name always 5 characters long? Or perhaps, is there a special character always dividing the base name and the number (rough_112.src so the divider is always an underscore)?

I am not sure when I have time to write this .bat script for you (busy with several things at the moment), but depending on your answers I guess I will have something for you to test on Monday.

(I enjoy those little scripting adventures)
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
 
crazyguy85
YaBB Newbies
*
Offline



Posts: 5
Re: Copy File When One Is Deleted
Reply #8 - Apr 11th, 2013 at 1:42pm
 
Gert wrote on Apr 5th, 2013 at 12:39pm:
I think I have everything I need.

Your remark

> If I have to copy the first file into this folder manually e.g E:\rough1.src and E:\rough1.dat to C:\roboter\krc\ then that is ok.

This really helps. This was the most difficult for me to find out. If you can do that yourself (copying the "1" files), it is a lot easier.

I will write a bat script for you that you can use with the "Run a .bat file" task ( http://www.watchdirectory.net/wdhelp/plugins/wdopAutoRunBat.html ), you let this task monitor C:\Roboter\KRC and let the task start the .bat file when it detects a deleted *.src (or *.dat, but not both) file.
The script will get the base-name from the deleted file (rough123.src -> rough)
The script will get the current "number" from the deleted file (rough123.src -> 123)
The script adds 1 to this number (124)
The script checks if E:\<base name><number>.src (E:\rough124.src) exists and if it does, copies it and its corresponding .dat file to C:\Roboter\KRC

Questions....
Those numbers (the 123 above) appended to the base name (rough), are they always like that (1,2,3,....,13,14,15,....,198,199,...) or do they have leading zeroes (001,002,003,004....,017,018,...)?
I assume their will never be any "holes" in this numbering (1,2,3,5,8,13), correct?
The base name ("rough" in our example), is there anything you can tell me about it? For example, is the base-name always 5 characters long? Or perhaps, is there a special character always dividing the base name and the number (rough_112.src so the divider is always an underscore)?

I am not sure when I have time to write this .bat script for you (busy with several things at the moment), but depending on your answers I guess I will have something for you to test on Monday.

(I enjoy those little scripting adventures)




Hi Gert,

Apologies for the delayed reply, I have been working away the past few days.

In answer to your questions,

1) The numbers have no leading zeroes and they will never have any "holes" in them.
2) The names of the files have no special characters, and it does not have to always be 5 characters long. They can be called anything at all, I usually use "rough".

I appreciate you taking the time to do this, as I was not expecting to have it done for me! There is no rush for this, I don't expect you to go out of your way for it. Thanks again
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2239
The Netherlands
Re: Copy File When One Is Deleted
Reply #9 - Apr 11th, 2013 at 3:59pm
 
Below is the script, not fully tested but I think it will work. Save the script as, for example, C:\Scripts\CopyNextSet.bat
Create a task using the "Run a .bat file" plugin - http://www.watchdirectory.net/wdhelp/plugins/wdopAutoRunBat.html
Let the task monitor C:\Roboter\KRC
On the "Events" window, only select FILEDEL
On "Filter Events" create a filter like:
When the File Extension equals SRC then process the event.

I hope you understand the script, I tried to make it as clear as possible.

Code:
rem settings for this script
rem - the drive letter of the USB - where are files to be copied located
SET USBDRIVE=E:
rem - where should files be copied to
SET FILETARGET=C:\Roboter\KRC

rem first check if we are called for the correct event
rem we expect to be called for a deleted *.src file
IF "%WD_REASON%" NEQ "FILEDEL" GOTO :EOF
IF "%WD_FILE_E%" NEQ "SRC" GOTO :EOF

rem for the file rough224.src, get the "rough" and "224" into separate variables
Call :SplitFileName
echo SP_NAME is "%SP_NAME%"
echo SP_NUM  is "%SP_NUM%"

rem we do not start copying new files until the corresponding *.dat file
rem is removed as well
Call :WaitForDeletedDatFile

rem check if the new set of files is on the USB, if not we are done
SET /A SP_NUM = %SP_NUM% + 1
IF NOT EXIST "%USBDRIVE%\%SP_NAME%%SP_NUM%.src" GOTO :EOF
rem copy the files
COPY "%USBDRIVE%\%SP_NAME%%SP_NUM%.src" "%FILETARGET%"
COPY "%USBDRIVE%\%SP_NAME%%SP_NUM%.dat" "%FILETARGET%"
rem done!
GOTO :EOF

:WaitForDeletedDatFile
rem sleep a little bit
"%WD_INSTDIR%\GdPUtil.exe" -sleep 1
IF NOT EXIST "%FILETARGET%\%WD_FILE_B%.dat" GOTO :EOF
GOTO :WaitForDeletedDatFile

:SplitFileName
SET SP_NAME=
SET SP_NUM=
SET WORK=%WD_FILE_B%
:SplitFileName_again
rem get the last pos of WORK
SET LP=%WORK:~-1%
rem is this numeric?
Call :CheckNumeric
IF "%RESULT%" EQU "N" (
   SET SP_NAME=%WORK%
   GOTO :EOF
)
SET SP_NUM=%LP%%SP_NUM%
rem remove the last pos from work
SET WORK=%WORK:~0,-1%
GOTO :SplitFileName_again

:CheckNumeric
SET RESULT=Y
IF "%LP%" EQU "0" GOTO :EOF
IF "%LP%" EQU "1" GOTO :EOF
IF "%LP%" EQU "2" GOTO :EOF
IF "%LP%" EQU "3" GOTO :EOF
IF "%LP%" EQU "4" GOTO :EOF
IF "%LP%" EQU "5" GOTO :EOF
IF "%LP%" EQU "6" GOTO :EOF
IF "%LP%" EQU "7" GOTO :EOF
IF "%LP%" EQU "8" GOTO :EOF
IF "%LP%" EQU "9" GOTO :EOF
SET RESULT=N
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
 
Page Index Toggle Pages: 1