If file exist

Discuss RoboTask here
Post Reply
mspitzh
Posts: 1
Joined: Thu Mar 14, 2024 11:11 am

If file exist

Post by mspitzh »

Hi,

maybe I am blind or stupid, but I don't find the function:

If file exist

/Matthias
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: If file exist

Post by Oleg »

Look at my example below.
Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.
Also you can simply copy task text and paste it into the task list.
Then you can see it in task editor

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
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task1465"
Hide=INTEGER|0
ID=INTEGER|1102468931
LogOnAsUser=INTEGER|1
Name=STRING|"If file exists"
OnErrorTaskID=INTEGER|0
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
StepPause=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""FileName"" with value ""C:\temp\test123.txt"""
Params=FOLDER

[Actions\Action1\Params]
_rt_variables_produced=STRING|"FileName"
expand=STRING|"0"
linecount=STRING|"1"
varname=STRING|"FileName"
varvalue=STRING|"C:\temp\test123.txt"

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

[Actions\Action2\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"0"
type=STRING|"3"
value1=STRING|"{FileExists({FileName})}"

[Actions\Action3]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""File ""{FileName}"" exists."""
Params=FOLDER

[Actions\Action3\Params]
icon=STRING|"1"
msg0=STRING|"File ""{FileName}"" exists."
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"

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

[Actions\Action5]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""File ""{FileName}"" does not exist."""
Params=FOLDER

[Actions\Action5\Params]
icon=STRING|"3"
msg0=STRING|"File ""{FileName}"" does not exist."
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"

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

Oleg Yershov
Lana_K
Posts: 30
Joined: Tue Jul 14, 2020 7:43 pm
Location: Bristol, UK

Re: If file exist

Post by Lana_K »

I use If Then flow with system variable {FileExists({TempDir}\file.tmp)} which is either true or false. But for me, oddly, the variable sometimes has correct value, sometimes does not.
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: If file exist

Post by Oleg »

The variable checks for the file existence at the moment this variable is called. But the file may appear somewhat later (for example, after 0.5 seconds).
So when you look at a folder in Windows Explorer, you see the file, but the variable returns FALSE

If your file should appear and you want to wait, I recommend using the Wait for file action and waiting a while. The action can also return TRUE or FALSE.
Oleg Yershov
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: If file exist

Post by Oleg »

I also recommend that you check the file for availability. Because file can be unavailable because it opened in another application.
For example, the file still being written. The file exists, but unavailable right now.
Look at the variable {IsFileFree(<Full_File_Name>)} or the action Wait for file with "Wait for accessibility of the file" option
Oleg Yershov
Lana_K
Posts: 30
Joined: Tue Jul 14, 2020 7:43 pm
Location: Bristol, UK

Re: If file exist

Post by Lana_K »

This is a good point, thank you, Oleg.
Another issue I ran into when checking if file exists is a set of special characters (I suspect they are something to do with BOM, but I am no expert) which is added at the beginning of some files created by Robotask in UTF-8 format file names. They are invisible to naked eye and I only figured this out when pasted various filenames into text to ASCII convertor. The cure I found is to switch from UTF-8 encoding to ANSI. This solved the problem.
Post Reply