Page 1 of 1

Is there a way to check file / folder?

Posted: 21 Feb 2017 02:56
by apshergill91
I was developing a flow in which I used delete folder action!
But it ended up in error as file/folder doesn't exist!

I want to check if or not file/folder exist before I perform any action on it, so as to avoid error!

How do I go about this thing, I found no condition for this?

Re: Is there a way to check file / folder?

Posted: 21 Feb 2017 09:58
by piskor
Hi

Check, if trigger "File observer" with checked "Delete Self" event type suits your needs
http://automagic4android.com/en/help/co ... e_observer

Re: Is there a way to check file / folder?

Posted: 21 Feb 2017 10:13
by apshergill91
Really appreciate your help!
But than no use I have to create different flow for this!
I want to use it main flow without modifying trigger!

Any condition or script that could do?
piskor wrote:Hi

Check, if trigger "File observer" with checked "Delete Self" event type suits your needs
http://automagic4android.com/en/help/co ... e_observer

Re: Is there a way to check file / folder?

Posted: 21 Feb 2017 11:55
by piskor
You can create new flow with file / folder availability check, and inside it set global variable to true if file / folder is available and then check this variable in first flow

It should looks like this:

First flow:
Your trigger
your commands
"Execute flows": second_flow_with_file_availability_check - this one sets global variable, for example global_file_av
Now you can use condition "Expression" with expression set to:
global_file_av == true
If true than delete folder
If false - stop thread or do something else :)

Re: Is there a way to check file / folder?

Posted: 22 Feb 2017 01:48
by apshergill91
Ok yup

Thanks
piskor wrote:You can create new flow with file / folder availability check, and inside it set global variable to true if file / folder is available and then check this variable in first flow

It should looks like this:

First flow:
Your trigger
your commands
"Execute flows": second_flow_with_file_availability_check - this one sets global variable, for example global_file_av
Now you can use condition "Expression" with expression set to:
global_file_av == true
If true than delete folder
If false - stop thread or do something else :)

Re: Is there a way to check file / folder?

Posted: 22 Feb 2017 11:09
by piskor
Hi again :)

I have found better and faster solution without need for another flow
Use action "Execute command" with command:
test -d /storage/emulated/0/DCIM && echo 1 || echo 0
stdout variable will be set to 1 if /storage/emulated/0/DCIM folder in this example is available or set to 0 if it is not available
you can change stdout variable name if you want and than check it using condition "Expression" as I proposed earlier

Re: Is there a way to check file / folder?

Posted: 22 Feb 2017 11:15
by apshergill91
Amazing job bro!
Automagic is also amazing..
piskor wrote:Hi again :)

I have found better and faster solution without need for another flow
Use action "Execute command" with command:
test -d /storage/emulated/0/DCIM && echo 1 || echo 0
stdout variable will be set to 1 if /storage/emulated/0/DCIM folder in this example is available or set to 0 if it is not available
you can change stdout variable name if you want and than check it using condition "Expression" as I proposed earlier

Re: Is there a way to check file / folder?

Posted: 22 Feb 2017 11:51
by piskor
I am using AM since one month and i'm still learning and looking for best solutions :)

Re: Is there a way to check file / folder?

Posted: 22 Feb 2017 11:56
by apshergill91
It's an amazing tool. But drains lots of battery.
I also started some years back, but due to battery issue left it, but now again back as got new mobile.
And now it seems to work better.
piskor wrote:I am using AM since one month and i'm still learning and looking for best solutions :)