isfilefree

Discuss RoboTask here
Post Reply
sen5241
Posts: 12
Joined: Sat Sep 11, 2004 8:56 am

isfilefree

Post by sen5241 »

i want to copy a large file in a folder through a network. If the file is completed, then i want to move it.
The copying takes for example about 2 minutes, sometimes even 6 minutes
If i use "{v} FileExists" then i get an error because the file is still in use (= being copied)
so i tried to make an "if then" with  "isfilefree" and then move the file
but this does not work.. Can you tell me why??
Is there perhaps a variable that can see if a file is still being copied(so "in use") or finshed???
regards, Richard
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

isfilefree

Post by Oleg »

"Isfilefree" macrovariable don't wait when the file will be released. It only tell you about file: it is free or not. If you want to wait for moment when the file will be released, you should use foolowing construction (for example):

Simple loop (0 ... 1000)
   if {isfilefree({myfile})} then
      do something ....
      break the loop
   end if
   wait (15 sec) // for example
end loop
if {Loop_variable} =1000 then
   WriteToLog 'File is locked!'
end if

But I not understand something. May be, you should do so in one task:

copy file from network
move it somewhere else

In this case you not need such complex algorithm.
sen5241
Posts: 12
Joined: Sat Sep 11, 2004 8:56 am

isfilefree

Post by sen5241 »


Hi Oleg
thanks for your quick reaction
I would like to explain what i am using it for
Actually it's very simple but i come across a lot of problems
I would like to have a folder in which *.mov's will be put. Sometimes big ones; maybe 1 gig copied over a network, sometimes smaller files copied locally I would like to have these files copied one after an other. So in the second folder only one fill will arrive at a time, then the other, etc
The problems i encoutered are:
-sometimes one will copiy 2 files at a time into the folder -sometimes one will copy one correct file and one different filetype -sometimes one wile copy a different file type -sometimes one wile copy a folder containig different file types -sometimes the connection is very slow and then it takes long for the file to copy, and the the file stays locked -etc
maybe you have a hint for me on how to fix this
the most important thing is that there may arrive only one file at a time no matter what is dumped in the folder at first
i have only little experience in robotask, but if this is solved then it looks very promising
regards, Richard
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

isfilefree

Post by Oleg »

How you launch the task?
I think that you use Folder monitor event to launch the task, right? Or you try to move all files which is placed in receiver folder periodicly?
I hope that I'm able to write sample task for you.
sen5241
Posts: 12
Joined: Sat Sep 11, 2004 8:56 am

isfilefree

Post by sen5241 »


Hi Oleg
At first i wanted to activate the task with a file monitor.
but after concerning perhaps it’s better to use cyclic monitor
for example: every minute it looks if anything has changed. If not then it does nothing
that might also fix the "file is free" problem.
I just think that then it might be more complex to copy them one by one in another folder
Regards, Richard
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

isfilefree

Post by Oleg »

See example task below. This task is trying to move all files from folder C:\receive\ to folder C:\process every 5 min. In normal status the folder C:\receive must be empty. As soon as new files has arrived the task tryes to move files to C:\process and waits when files will be released during 10 min. See parameters: max. 60 attempts and pause between attempts 10 sec.

More complex task with using File Monitor will be in next posting.

Save text of task into any file and choose Menu | Task | Import to import into RoboTask

;**********************
;* RoboTask Task file *
;* Do not edit!       *
;**********************

[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|565106205
ContinueOnError=INTEGER|0
Events=FOLDER
ExternalName=STRING|"Task9"
Hide=INTEGER|0
ID=INTEGER|980072074
Name=STRING|"IsFileFree demo"
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3

[Actions]
Action1=FOLDER
Action10=FOLDER
Action11=FOLDER
Action12=FOLDER
Action13=FOLDER
Action14=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_LOOP_FILE"
Enabled=INTEGER|-1
Name=STRING|"File Loop"
Params=FOLDER

[Actions\Action1\Params]
createmode=STRING|"1"
date1=STRING|"20050417"
date2=STRING|"20050417"
destvar=STRING|"FILE_TO_MOVE"
DuringDays=STRING|"1"
DuringMonths=STRING|"1"
file0=STRING|"C:\receive\*.*"
filecount=STRING|"1"
OlderDays=STRING|"1"
OlderMonths=STRING|"1"
savesize=STRING|"0"
subdirs=STRING|"0"
timesize=STRING|"0"
WithoutPath=STRING|"0"

[Actions\Action10]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action10\Params]
message=STRING|"File ""{File_To_Move}"" not accessible!"
type=STRING|"2"

[Actions\Action11]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action12]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"

[Actions\Action13]
ActionID=STRING|"A_VARIABLES_REMOVE"
Enabled=INTEGER|-1
Name=STRING|"Remove variable ""TRY_COUNT"""
Params=FOLDER

[Actions\Action13\Params]
varname=STRING|"TRY_COUNT"

[Actions\Action14]
ActionID=STRING|"A_VARIABLES_REMOVE"
Enabled=INTEGER|-1
Name=STRING|"Remove variable ""FILE_TO_MOVE"""
Params=FOLDER

[Actions\Action14\Params]
varname=STRING|"FILE_TO_MOVE"

[Actions\Action2]
ActionID=STRING|"A_LOOP_SIMPLE"
Enabled=INTEGER|-1
Name=STRING|"Simple Loop"
Params=FOLDER

[Actions\Action2\Params]
begin=STRING|"0"
end=STRING|"60"
variable=STRING|"TRY_COUNT"

[Actions\Action3]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action3\Params]
case=STRING|"0"
operator=STRING|"0"
type=STRING|"3"
value1=STRING|"{IsFileFree({File_To_Move})}"

[Actions\Action4]
ActionID=STRING|"A_FILE_COPY"
Enabled=INTEGER|-1
Name=STRING|"Copy/Move File"
Params=FOLDER

[Actions\Action4\Params]
destdir=STRING|"C:\process"
f_count=STRING|"1"
file0=STRING|"{File_To_Move}"
ifexists=STRING|"1"
move=STRING|"1"
subdir=STRING|"0"

[Actions\Action5]
ActionID=STRING|"A_LOOP_BREAK"
Enabled=INTEGER|-1
Name=STRING|"Break"

[Actions\Action6]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action7]
ActionID=STRING|"A_GENERAL_PAUSE"
Enabled=INTEGER|-1
Name=STRING|"Delay 10000 ms"
Params=FOLDER

[Actions\Action7\Params]
delay=STRING|"100"

[Actions\Action8]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"

[Actions\Action9]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action9\Params]
case=STRING|"0"
operator=STRING|"2"
type=STRING|"1"
value1=STRING|"{Try_Count}"
value2=STRING|"60"

[Events]
Event1=FOLDER

[Events\Event1]
Enabled=INTEGER|-1
EventID=STRING|"E_GENERAL_CYCLIC"
Params=FOLDER

[Events\Event1\Params]
id=STRING|"92EJH9VW"
interval=STRING|"300"
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

isfilefree

Post by Oleg »

Example with using File Monitor below. Pay attention that at starting of the task it is disabled. At ending of task it is enabled again. It is important, file monitor is turned off at time of task execution. If file monitor event is fired during task execution, task may lost changes of C:\receive folder.

Choose any task you like. If any question - ask me, please. Do not forget to enable imported task.

;**********************
;* RoboTask Task file *
;* Do not edit!       *
;**********************

[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|565106205
ContinueOnError=INTEGER|0
Events=FOLDER
ExternalName=STRING|"Task23"
Hide=INTEGER|0
ID=INTEGER|461376059
Name=STRING|"IsFileFree demo - 2"
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3

[Actions]
Action1=FOLDER
Action10=FOLDER
Action11=FOLDER
Action12=FOLDER
Action13=FOLDER
Action14=FOLDER
Action15=FOLDER
Action16=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_TASKS_DISABLE"
Enabled=INTEGER|-1
Name=STRING|"Disable Task ""IsFileFree demo - 2"""
Params=FOLDER

[Actions\Action1\Params]
taskid=STRING|"461376059"

[Actions\Action10]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action10\Params]
case=STRING|"0"
operator=STRING|"2"
type=STRING|"1"
value1=STRING|"{Try_Count}"
value2=STRING|"60"

[Actions\Action11]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action11\Params]
message=STRING|"File ""{File_To_Move}"" not accessible!"
type=STRING|"2"

[Actions\Action12]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action13]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"

[Actions\Action14]
ActionID=STRING|"A_VARIABLES_REMOVE"
Enabled=INTEGER|-1
Name=STRING|"Remove variable ""TRY_COUNT"""
Params=FOLDER

[Actions\Action14\Params]
varname=STRING|"TRY_COUNT"

[Actions\Action15]
ActionID=STRING|"A_VARIABLES_REMOVE"
Enabled=INTEGER|-1
Name=STRING|"Remove variable ""FILE_TO_MOVE"""
Params=FOLDER

[Actions\Action15\Params]
varname=STRING|"FILE_TO_MOVE"

[Actions\Action16]
ActionID=STRING|"A_TASKS_ENABLE"
Enabled=INTEGER|-1
Name=STRING|"Enable Task ""IsFileFree demo - 2"""
Params=FOLDER

[Actions\Action16\Params]
taskid=STRING|"461376059"

[Actions\Action2]
ActionID=STRING|"A_LOOP_TEXT"
Enabled=INTEGER|-1
Name=STRING|"Text Loop"
Params=FOLDER

[Actions\Action2\Params]
destvar=STRING|"FILE_TO_MOVE"
file=STRING|"{TempDir}\FilesToMove.txt"
linecount=STRING|"0"
sourcetext=STRING|"0"

[Actions\Action3]
ActionID=STRING|"A_LOOP_SIMPLE"
Enabled=INTEGER|-1
Name=STRING|"Simple Loop"
Params=FOLDER

[Actions\Action3\Params]
begin=STRING|"0"
end=STRING|"60"
variable=STRING|"TRY_COUNT"

[Actions\Action4]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action4\Params]
case=STRING|"0"
operator=STRING|"0"
type=STRING|"3"
value1=STRING|"{IsFileFree({File_To_Move})}"

[Actions\Action5]
ActionID=STRING|"A_FILE_COPY"
Enabled=INTEGER|-1
Name=STRING|"Copy/Move File"
Params=FOLDER

[Actions\Action5\Params]
destdir=STRING|"C:\process"
f_count=STRING|"1"
file0=STRING|"{File_To_Move}"
ifexists=STRING|"1"
move=STRING|"1"
subdir=STRING|"0"

[Actions\Action6]
ActionID=STRING|"A_LOOP_BREAK"
Enabled=INTEGER|-1
Name=STRING|"Break"

[Actions\Action7]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action8]
ActionID=STRING|"A_GENERAL_PAUSE"
Enabled=INTEGER|-1
Name=STRING|"Delay 10000 ms"
Params=FOLDER

[Actions\Action8\Params]
delay=STRING|"100"

[Actions\Action9]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"

[Events]
Event1=FOLDER

[Events\Event1]
Enabled=INTEGER|-1
EventID=STRING|"E_FILE_MONITOR"
Params=FOLDER

[Events\Event1\Params]
chg=STRING|"0"
chga=STRING|"1"
chgsl=STRING|"1"
chgsm=STRING|"1"
chgtl=STRING|"1"
chgtm=STRING|"1"
del=STRING|"0"
folder1=STRING|"C:\receive"
foldercount=STRING|"1"
id=STRING|"PRNW9GHQ6"
incmask=STRING|"*.*"
interval=STRING|"15"
listmode=STRING|"2"
mon_files=STRING|"1"
mon_folders=STRING|"0"
new=STRING|"1"
newlist=STRING|"{TempDir}\FilesToMove.txt"
saveresults=STRING|"1"
subfolders1=STRING|"0"
sen5241
Posts: 12
Joined: Sat Sep 11, 2004 8:56 am

isfilefree

Post by sen5241 »


Hi Oleg
With your script more and more it gets clearer on how to do this
I've just got another question on how to get the files one-after-another in another folder
and another file is only allowed in the folder after the last one is deleted
And ofcourse thank you very much for the example !!! 
Regards, Richard
sen5241
Posts: 12
Joined: Sat Sep 11, 2004 8:56 am

isfilefree

Post by sen5241 »

examples !!!!
Post Reply