Is there a way to check file / folder?

General discussions about Automagic and automation in general

Moderator: Martin

Post Reply
apshergill91
Posts: 18
Joined: 07 Dec 2013 05:59

Is there a way to check file / folder?

Post by apshergill91 » 21 Feb 2017 02:56

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?

piskor
Posts: 16
Joined: 20 Dec 2016 13:03

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

Post by piskor » 21 Feb 2017 09:58

Hi

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

apshergill91
Posts: 18
Joined: 07 Dec 2013 05:59

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

Post by apshergill91 » 21 Feb 2017 10:13

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

piskor
Posts: 16
Joined: 20 Dec 2016 13:03

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

Post by piskor » 21 Feb 2017 11:55

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 :)
Regards, piskor

apshergill91
Posts: 18
Joined: 07 Dec 2013 05:59

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

Post by apshergill91 » 22 Feb 2017 01:48

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 :)

piskor
Posts: 16
Joined: 20 Dec 2016 13:03

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

Post by piskor » 22 Feb 2017 11:09

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
Regards, piskor

apshergill91
Posts: 18
Joined: 07 Dec 2013 05:59

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

Post by apshergill91 » 22 Feb 2017 11:15

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

piskor
Posts: 16
Joined: 20 Dec 2016 13:03

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

Post by piskor » 22 Feb 2017 11:51

I am using AM since one month and i'm still learning and looking for best solutions :)
Regards, piskor

apshergill91
Posts: 18
Joined: 07 Dec 2013 05:59

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

Post by apshergill91 » 22 Feb 2017 11:56

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 :)

Post Reply