How can create a job for download latest file from a foler

Discuss RoboTask here
Post Reply
baber
Posts: 5
Joined: Wed Oct 21, 2015 1:34 pm

How can create a job for download latest file from a foler

Post by baber »

Dear all
Hi

I want do in robotask this job can you help me??

I have a folder that every 1 hours put a file on that
The name of files is :

Batch-960521-03.zip

And the other file automatically that put in folder is

Batch-960521-04.zip

Now in robotask how can create a job that run every 2 hours for download just latest file ??

Br
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: How can create a job for download latest file from a fol

Post by Oleg »

Yes of course you can do this.
Look at my example below

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|444033236
Comment=STRINGLIST
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task283"
Hide=INTEGER|0
ID=INTEGER|1805526001
LogOnAsUser=INTEGER|1
Name=STRING|"Get oldest file from the folder"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""FOLDER"" with value ""d:\incoming"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
varname=STRING|"FOLDER"
varvalue=STRING|"d:\incoming"

[Actions\Action2]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""FILENAME"" with value """""
Params=FOLDER

[Actions\Action2\Params]
expand=STRING|"0"
varname=STRING|"FILENAME"

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

[Actions\Action3\Params]
createmode=STRING|"1"
date1=STRING|"20170812"
date2=STRING|"20170812"
destvar=STRING|"FILENAME"
DuringDays=STRING|"1"
DuringHours=STRING|"1"
DuringMinutes=STRING|"1"
DuringMonths=STRING|"1"
file0=STRING|"{Folder}\*.zip"
filecount=STRING|"1"
OlderDays=STRING|"1"
OlderHours=STRING|"1"
OlderMinutes=STRING|"1"
OlderMonths=STRING|"1"
savesize=STRING|"0"
searchkind=STRING|"0"
sort=STRING|"1"
sortby=STRING|"1"
sortorder=STRING|"0"
subdirs=STRING|"1"
timesize=STRING|"0"
WithoutPath=STRING|"0"

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

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

[Actions\Action5\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"7"
type=STRING|"0"
value1=STRING|"{FileName}"

[Actions\Action6]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""No files"""
Params=FOLDER

[Actions\Action6\Params]
icon=STRING|"0"
msg0=STRING|"No files"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action7]
ActionID=STRING|"A_FLOW_ELSE"
Enabled=INTEGER|-1
Name=STRING|"Else"

[Actions\Action8]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""The latest file is ""{FileName}"""""
Params=FOLDER

[Actions\Action8\Params]
icon=STRING|"1"
msg0=STRING|"The latest file is ""{FileName}"""
msg2=STRING|"You can put here your actions "
msg3=STRING|"copy file to local folders or somthing else "
msgcount=STRING|"4"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action9]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"
Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.

The main problem - you have to determine the oldest file in the folder
You can do this If you sort the list of files by filetime.
Look at the step #3 (File Loop)
FileLoopSort.png
FileLoopSort.png (27.5 KiB) Viewed 22803 times
After the loop the variable FileName will contain the name of oldest file in the folder.
Oleg Yershov
baber
Posts: 5
Joined: Wed Oct 21, 2015 1:34 pm

Re: How can create a job for download latest file from a fol

Post by baber »

so thanks

but i realy confused with your code
is there any object in robotask that during create a job check that and it understand have to download latest file ?

because writing codes is not suitable can i define that from gui ?

BR
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: How can create a job for download latest file from a fol

Post by Oleg »

Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.
Next you can open the task in task editor and see details
Oleg Yershov
baber
Posts: 5
Joined: Wed Oct 21, 2015 1:34 pm

Re: How can create a job for download latest file from a fol

Post by baber »

thabks

i have imported the task now it has 9 step

1-Set variable "FOLDER" with value "d:\incoming"
2-Set variable "FILENAME" with value ""
3- File Loop
4-End Loop
5-If Then
6 - Show No File
7 - Else
8 - Show "The latest file is "{FileName}""
9 - End If

but realy don't understand some steps 1 when editing in variable name box you write : FOLDER
in variable value write : d:\incoming

in step2 you write variable name = FILENAME
in step3 you write in search for files box :{Folder}\*.zip
in step6 in Message text you write : No files
and in Message icons select Exclamation

in step8 in MessageText you write : The latest file is "{FileName}"

You can put here your actions
copy file to local folders or somthing else

and Message Icon you select Information

can you some explain what does means these steps ?

and i want download latest file but in the name you write Get oldest file from the folder (imported)


BR
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: How can create a job for download latest file from a fol

Post by Oleg »

These steps are the steps of algorithm of the task.
#1 Set the folder name where are your files to variable FOLDER
#2 set initial value to variable FileName
#3-#4 The loop which enumerates all specified files ({Folder}\*.zip)
#5 Checks the value in variable FileName after the loop
Steps #6 and #8 are information alerts only
You can place your own steps instead of step #8 to copy file somewhere or do some another actions with the file.
and i want download latest file but in the name you write Get oldest file from the folder (imported)
Where is your file? My example works if necessary folder is in your computer or on server in your local network.

It will be another algorithm for FTP or sFTP severs.
Oleg Yershov
baber
Posts: 5
Joined: Wed Oct 21, 2015 1:34 pm

Re: How can create a job for download latest file from a fol

Post by baber »

i want ti download newest file and then extract that on the other folder and finally FTP extracted file
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: How can create a job for download latest file from a fol

Post by Oleg »

Look at the example for FTP below

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|444033236
Comment=STRINGLIST
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task91"
Hide=INTEGER|0
ID=INTEGER|428259258
LogOnAsUser=INTEGER|1
Name=STRING|"download oldest file from FTP"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

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

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""FOLDER"" with value ""/MyFolder"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
varname=STRING|"FOLDER"
varvalue=STRING|"/MyFolder"

[Actions\Action10]
ActionID=STRING|"A_SSLFTP_DOWNLOAD"
Enabled=INTEGER|-1
Name=STRING|"SSL FTP Download"
Params=FOLDER

[Actions\Action10\Params]
file=STRING|"{FileName}"
folder=STRING|"{DestFolder}"
ifexists=STRING|"1"

[Actions\Action11]
ActionID=STRING|"A_ZIP_EXTRACT"
Enabled=INTEGER|-1
Name=STRING|"Extract Files"
Params=FOLDER

[Actions\Action11\Params]
destdir=STRING|"{DestFolder}\extract"
filetounzip=STRING|"{DestFolder}\{ExtractFileName({FileName})}"
overwrite=STRING|"0"
password=STRING|"2540125453264802519526730"
passwordmode=STRING|"0"
skipolderfiles=STRING|"0"
unzipfiles=STRING|"*.*"
usefoldernames=STRING|"1"

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

[Actions\Action2]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""DESTFOLDER"" with value ""C:\incomingFolder"""
Params=FOLDER

[Actions\Action2\Params]
expand=STRING|"0"
varname=STRING|"DESTFOLDER"
varvalue=STRING|"C:\incomingFolder"

[Actions\Action3]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""FILENAME"" with value """""
Params=FOLDER

[Actions\Action3\Params]
expand=STRING|"0"
varname=STRING|"FILENAME"

[Actions\Action4]
ActionID=STRING|"A_SSLFTP_LOGON"
Enabled=INTEGER|-1
Name=STRING|"SSL FTP Log On"
Params=FOLDER

[Actions\Action4\Params]
anonymous=STRING|"0"
host=STRING|"ftp.company.com"
passive=STRING|"1"
password=STRING|"4102541882429244164041117"
port=STRING|"21"
proxypassword=STRING|"2540125453267362545625453"
proxytype=STRING|"3"
tlsmode=STRING|"0"
useproxy=STRING|"0"
username=STRING|"username"
usessl2=STRING|"0"
usessl3=STRING|"0"
usestls=STRING|"1"
usestls11=STRING|"1"
usestls12=STRING|"1"

[Actions\Action5]
ActionID=STRING|"A_SSLFTP_FILELOOP"
Enabled=INTEGER|-1
Name=STRING|"SSL FTP File Loop"
Params=FOLDER

[Actions\Action5\Params]
createmode=STRING|"1"
date1=STRING|"18991230"
date2=STRING|"18991230"
DuringDays=STRING|"1"
DuringHours=STRING|"1"
DuringMinutes=STRING|"1"
DuringMonths=STRING|"1"
filenameonly=STRING|"0"
folder=STRING|"{Folder}/*.zip"
kind=STRING|"0"
OlderDays=STRING|"1"
OlderHours=STRING|"1"
OlderMinutes=STRING|"1"
OlderMonths=STRING|"1"
sizesave=STRING|"0"
sort=STRING|"1"
sortby=STRING|"1"
sortorder=STRING|"0"
subfolders=STRING|"0"
timesave=STRING|"0"

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

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

[Actions\Action7\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"7"
type=STRING|"0"
value1=STRING|"{FileName}"

[Actions\Action8]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""No files found"""
Params=FOLDER

[Actions\Action8\Params]
icon=STRING|"0"
msg0=STRING|"No files found"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action9]
ActionID=STRING|"A_FLOW_ELSE"
Enabled=INTEGER|-1
Name=STRING|"Else"
Algorithm is similar to my previous example.

Of course you can change folder names at steps #1 and #2
Also use your own FTP authorization parameters at the step #4
Oleg Yershov
Post Reply