Error when try to delete a file wich not exist

Post your questions and help other users.

Moderator: Martin

Post Reply
wfrcrd
Posts: 116
Joined: 27 May 2015 08:57

Error when try to delete a file wich not exist

Post by wfrcrd » 17 Sep 2016 16:59

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 ...

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

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

Post by Martin » 18 Sep 2016 16:58

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

wfrcrd
Posts: 116
Joined: 27 May 2015 08:57

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

Post by wfrcrd » 18 Sep 2016 22:28

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!!

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

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

Post by Martin » 19 Sep 2016 20:52

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

wfrcrd
Posts: 116
Joined: 27 May 2015 08:57

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

Post by wfrcrd » 21 Sep 2016 17:30

Thank youuu!!!

wfrcrd
Posts: 116
Joined: 27 May 2015 08:57

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

Post by wfrcrd » 26 Sep 2017 12:06

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 .

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

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

Post by Desmanto » 26 Sep 2017 15:01

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)
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

wfrcrd
Posts: 116
Joined: 27 May 2015 08:57

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

Post by wfrcrd » 26 Sep 2017 15:27

Yes I've done !!!

Really thank you!!!

Post Reply