I need help writing a task to do the following:
1) Monitor a folder for incoming *.csv files-several files could be received at the same time.
2)Capture the file name(s)
3)Pass the captured filenames to a program like MS Excel for processing on the individual files. Excel would need to process them individually-one at a time-wheter it was 1 or 100 files that were received at the same time. I don't need the Excel code.
4)After processing by MS Excel the files just processed would need to be renamed bt Robotask with the date and time added and moved from the incoming directory to the permanent directory.
5)Other files may be incoming when all of this is going on so it has to be able to handle that by recognizing that additional files arrived while it was busy processing the other files and repeat the process.
Thanks for any help that you can offer!
Passing Files to another application
Passing Files to another application
I wrote two sample tasks, see below.
First task processes CSV files. I don't know what you want to do in Excel, therefore I simply open it. Pay attention that the first step is "Disable task". It is necessary to turn off "File monitor" event during task execution. Otherwise you can miss some incoming files. This task works with folders c:\incoming and c:\permanent
Second task waits for finishing of first task and enables it again.
Both tasks must work together.
Save text of tasks into separated files and import into RoboTask by using menu Task | Import
;First 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|"Task266"
Hide=INTEGER|0
ID=INTEGER|770885367
Name=STRING|"Monitor CSV-files"
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
[Actions]
Action1=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 ""Monitor CSV files"""
Params=FOLDER
[Actions\Action1\Params]
taskid=STRING|"770885367"
[Actions\Action2]
ActionID=STRING|"A_TASKS_START"
Enabled=INTEGER|-1
Name=STRING|"Start Task ""Monotor CSV enable"""
Params=FOLDER
[Actions\Action2\Params]
taskid=STRING|"155141781"
wait=STRING|"0"
[Actions\Action3]
ActionID=STRING|"A_LOOP_TEXT"
Enabled=INTEGER|-1
Name=STRING|"Text Loop"
Params=FOLDER
[Actions\Action3\Params]
destvar=STRING|"CUR_CSV"
file=STRING|"c:\new_csv.txt"
linecount=STRING|"0"
sourcetext=STRING|"0"
[Actions\Action4]
ActionID=STRING|"A_GENERAL_RUN_PROG"
Enabled=INTEGER|-1
Name=STRING|"Run ""EXCEL.EXE"""
Params=FOLDER
[Actions\Action4\Params]
params=STRING|"{Cur_csv}"
program=STRING|"C:\Program Files\Microsoft Office\Office10\EXCEL.EXE"
runas=STRING|"0"
wait=STRING|"2"
[Actions\Action5]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""NEW_CSV"" with value ""{ExtractFileNameNoExt({cur_csv})}{Year}{MonthNo}{Day}{Hour s}{Minutes}{Seconds}.{ExtractFileExt({cur_csv})}"""
Params=FOLDER
[Actions\Action5\Params]
expand=STRING|"1"
varname=STRING|"NEW_CSV"
varvalue=STRING|"{ExtractFileNameNoExt({cur_csv})}{Year}{Mon thNo}{Day}{Hours}{Minutes}{Seconds}.{ExtractFileExt({cur_csv })}"
[Actions\Action6]
ActionID=STRING|"A_FILE_RENAME"
Enabled=INTEGER|-1
Name=STRING|"Rename File"
Params=FOLDER
[Actions\Action6\Params]
count=STRING|"1"
file0=STRING|"{cur_csv}"
mask=STRING|"{new_csv}"
subdirs=STRING|"0"
[Actions\Action7]
ActionID=STRING|"A_FILE_COPY"
Enabled=INTEGER|-1
Name=STRING|"Copy/Move File"
Params=FOLDER
[Actions\Action7\Params]
destdir=STRING|"C:\permanent"
f_count=STRING|"1"
file0=STRING|"{ExtractFilePath({cur_csv})}\{new_csv}"
ifexists=STRING|"1"
move=STRING|"1"
subdir=STRING|"0"
[Actions\Action8]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"
[Actions\Action9]
ActionID=STRING|"A_FILE_DELETE"
Enabled=INTEGER|-1
Name=STRING|"Delete File"
Params=FOLDER
[Actions\Action9\Params]
Count=STRING|"1"
deletedirs=STRING|"0"
file0=STRING|"c:\new_csv.txt"
subdir=STRING|"0"
ToRecycleBin=STRING|"0"
[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:\incoming"
foldercount=STRING|"1"
id=STRING|"TWVQICEZV"
incmask=STRING|"*.csv"
interval=STRING|"5"
listmode=STRING|"2"
mon_files=STRING|"1"
mon_folders=STRING|"0"
new=STRING|"1"
newlist=STRING|"c:\new_csv.txt"
saveresults=STRING|"1"
subfolders1=STRING|"1"
;Second task
;**********************
;* RoboTask Task file *
;* Do not edit! *
;**********************
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|565106205
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task267"
Hide=INTEGER|0
ID=INTEGER|155141781
Name=STRING|"Monitor CSV enable"
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
[Actions]
Action1=FOLDER
Action2=FOLDER
[Actions\Action1]
ActionID=STRING|"A_TASK_WAITCOMPETE"
Enabled=INTEGER|-1
Name=STRING|"Waiting for completion ""Monitor CSV files"" infinity"
Params=FOLDER
[Actions\Action1\Params]
taskid=STRING|"770885367"
wait=STRING|"0"
[Actions\Action2]
ActionID=STRING|"A_TASKS_ENABLE"
Enabled=INTEGER|-1
Name=STRING|"Enable Task ""Monitor CSV files"""
Params=FOLDER
[Actions\Action2\Params]
taskid=STRING|"770885367"
First task processes CSV files. I don't know what you want to do in Excel, therefore I simply open it. Pay attention that the first step is "Disable task". It is necessary to turn off "File monitor" event during task execution. Otherwise you can miss some incoming files. This task works with folders c:\incoming and c:\permanent
Second task waits for finishing of first task and enables it again.
Both tasks must work together.
Save text of tasks into separated files and import into RoboTask by using menu Task | Import
;First 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|"Task266"
Hide=INTEGER|0
ID=INTEGER|770885367
Name=STRING|"Monitor CSV-files"
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
[Actions]
Action1=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 ""Monitor CSV files"""
Params=FOLDER
[Actions\Action1\Params]
taskid=STRING|"770885367"
[Actions\Action2]
ActionID=STRING|"A_TASKS_START"
Enabled=INTEGER|-1
Name=STRING|"Start Task ""Monotor CSV enable"""
Params=FOLDER
[Actions\Action2\Params]
taskid=STRING|"155141781"
wait=STRING|"0"
[Actions\Action3]
ActionID=STRING|"A_LOOP_TEXT"
Enabled=INTEGER|-1
Name=STRING|"Text Loop"
Params=FOLDER
[Actions\Action3\Params]
destvar=STRING|"CUR_CSV"
file=STRING|"c:\new_csv.txt"
linecount=STRING|"0"
sourcetext=STRING|"0"
[Actions\Action4]
ActionID=STRING|"A_GENERAL_RUN_PROG"
Enabled=INTEGER|-1
Name=STRING|"Run ""EXCEL.EXE"""
Params=FOLDER
[Actions\Action4\Params]
params=STRING|"{Cur_csv}"
program=STRING|"C:\Program Files\Microsoft Office\Office10\EXCEL.EXE"
runas=STRING|"0"
wait=STRING|"2"
[Actions\Action5]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""NEW_CSV"" with value ""{ExtractFileNameNoExt({cur_csv})}{Year}{MonthNo}{Day}{Hour s}{Minutes}{Seconds}.{ExtractFileExt({cur_csv})}"""
Params=FOLDER
[Actions\Action5\Params]
expand=STRING|"1"
varname=STRING|"NEW_CSV"
varvalue=STRING|"{ExtractFileNameNoExt({cur_csv})}{Year}{Mon thNo}{Day}{Hours}{Minutes}{Seconds}.{ExtractFileExt({cur_csv })}"
[Actions\Action6]
ActionID=STRING|"A_FILE_RENAME"
Enabled=INTEGER|-1
Name=STRING|"Rename File"
Params=FOLDER
[Actions\Action6\Params]
count=STRING|"1"
file0=STRING|"{cur_csv}"
mask=STRING|"{new_csv}"
subdirs=STRING|"0"
[Actions\Action7]
ActionID=STRING|"A_FILE_COPY"
Enabled=INTEGER|-1
Name=STRING|"Copy/Move File"
Params=FOLDER
[Actions\Action7\Params]
destdir=STRING|"C:\permanent"
f_count=STRING|"1"
file0=STRING|"{ExtractFilePath({cur_csv})}\{new_csv}"
ifexists=STRING|"1"
move=STRING|"1"
subdir=STRING|"0"
[Actions\Action8]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"
[Actions\Action9]
ActionID=STRING|"A_FILE_DELETE"
Enabled=INTEGER|-1
Name=STRING|"Delete File"
Params=FOLDER
[Actions\Action9\Params]
Count=STRING|"1"
deletedirs=STRING|"0"
file0=STRING|"c:\new_csv.txt"
subdir=STRING|"0"
ToRecycleBin=STRING|"0"
[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:\incoming"
foldercount=STRING|"1"
id=STRING|"TWVQICEZV"
incmask=STRING|"*.csv"
interval=STRING|"5"
listmode=STRING|"2"
mon_files=STRING|"1"
mon_folders=STRING|"0"
new=STRING|"1"
newlist=STRING|"c:\new_csv.txt"
saveresults=STRING|"1"
subfolders1=STRING|"1"
;Second task
;**********************
;* RoboTask Task file *
;* Do not edit! *
;**********************
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|565106205
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task267"
Hide=INTEGER|0
ID=INTEGER|155141781
Name=STRING|"Monitor CSV enable"
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
[Actions]
Action1=FOLDER
Action2=FOLDER
[Actions\Action1]
ActionID=STRING|"A_TASK_WAITCOMPETE"
Enabled=INTEGER|-1
Name=STRING|"Waiting for completion ""Monitor CSV files"" infinity"
Params=FOLDER
[Actions\Action1\Params]
taskid=STRING|"770885367"
wait=STRING|"0"
[Actions\Action2]
ActionID=STRING|"A_TASKS_ENABLE"
Enabled=INTEGER|-1
Name=STRING|"Enable Task ""Monitor CSV files"""
Params=FOLDER
[Actions\Action2\Params]
taskid=STRING|"770885367"
Passing Files to another application
It works when I set the 1st task to copy/move files to a new folder and then start the 2nd task-using folder monitor-to disable the 1st task, execute all commands then end with reenabling the 1st task.
There is a problem however "File monitor" doesn't work unless the following 3 filter selections are made 1)Watch for new files 2) monitor folders 3)monitor files
Cyclic seems to be more reliable, it works flawlessly. Is their a reason why I shouldn't use it instead?
I need another code: How do I make Robotask move one file at a time (even if there are several files in the same folder) and giving the moved file the same name every time. Then looping until all the files in the directory have been moved and renamed to the same file name. Then ending if there are no other files to be moved and renamed. Note: the renamed file is deleted before it loops back to get any other files so I won't have any filename conflicts.
Thanks for the help.
There is a problem however "File monitor" doesn't work unless the following 3 filter selections are made 1)Watch for new files 2) monitor folders 3)monitor files
Cyclic seems to be more reliable, it works flawlessly. Is their a reason why I shouldn't use it instead?
I need another code: How do I make Robotask move one file at a time (even if there are several files in the same folder) and giving the moved file the same name every time. Then looping until all the files in the directory have been moved and renamed to the same file name. Then ending if there are no other files to be moved and renamed. Note: the renamed file is deleted before it loops back to get any other files so I won't have any filename conflicts.
Thanks for the help.
Passing Files to another application
There is a "File Loop" for this purpose. Do the following steps in your task:I need another code: How do I make Robotask move one file at a time (even if there are several files in the same folder) and giving...
File loop
Rename current file to FixedName.dat
Process FixedName.dat //one or more operations
Remove FixedName.dat
End loop