Page 1 of 1

Error when try to delete a file wich not exist

Posted: 17 Sep 2016 16:59
by wfrcrd
How can I avoid it?
The error message stop the flow, it's not just a "warning" message.
The file I'm trying to delete sometimes exist and sometimes don't.
It's hard for me to evaluate the presence of that file.
How can I manage it?

Really thank you ...

Re: Error when try to delete a file wich not exist

Posted: 18 Sep 2016 16:58
by Martin
Hi,

You can either use a condition Expression: existsFile(pathToFile) to check if the file exists or use action Init Variables File Info to test it and store the result in variable file_exists.

Alternatively you can also catch the exception. To do this, append an action like Notification on Screen to the action that produces the exception. Select the connection between the two actions, press edit and change the type to 'Exception'. The notification-action will only be executed when the first action produces an exception. Automagic will not stop the flow in this case and will not show an error by itself.

Regards,
Martin

Re: Error when try to delete a file wich not exist

Posted: 18 Sep 2016 22:28
by wfrcrd
The second way (exception) works for me.

Anyway I tried the first too but I can't wrte the Expression correctly (as usual),
the expression line is :

existsFile(/storage/extSdCard/.dir/file.txt)

and it's wrong.

but the string "/storage/extSdCard/.dir/file.txt" it's the same that I use in the other flow to write that file (and of course it works).

How should I write the Expression?

Thank you!!

Re: Error when try to delete a file wich not exist

Posted: 19 Sep 2016 20:52
by Martin
Hi,

You have to surround the path with double quotes since the value is a string:
existsFile("/storage/extSdCard/.dir/file.txt")

or you could assign the path to a variable first:
path = "/storage/extSdCard/.dir/file.txt";
existsFile(path)

Regards,
Martin

Re: Error when try to delete a file wich not exist

Posted: 21 Sep 2016 17:30
by wfrcrd
Thank youuu!!!

Re: Error when try to delete a file wich not exist

Posted: 26 Sep 2017 12:06
by wfrcrd
Hi !
I resume this old post because I need to check a condition before to move some files :
the condition should be if almost one of file with a specific extension (for example "txt") exist,
then move all the files to another directory.

So I've tried this way

existsFile("/storage/extSdCard/.dir/*.txt")

but the "*" seems not working.
How can I solve it?

Thank you .

Re: Error when try to delete a file wich not exist

Posted: 26 Sep 2017 15:01
by Desmanto
AFAIK, you can't use wild card/pattern at that function.

You should use Init variable File list, match every file with .txt (replace the path as needed)
File Pattern : /storage/extSdCard/.dir/*.txt

and check using expression if {files} is empty
Expression : isEmpty(files)

Then move the files if false (false mean .txt files exist)

Re: Error when try to delete a file wich not exist

Posted: 26 Sep 2017 15:27
by wfrcrd
Yes I've done !!!

Really thank you!!!