Help on the better way to copy/move files

Post your questions and help other users.

Moderator: Martin

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

Help on the better way to copy/move files

Post by wfrcrd » 22 Jan 2018 08:42

Hi to everyone,
I'm trying to copy/move files and I'm facing with some problem (strange)
I made a flow that seems working but I'm pretty sure it's not the better way to do it.
The target is to copy/move the files automatically downloaded from other apps (Whatsapp or facebook messenger for example)
to another directory (in the future I'd like to copy them to different directories, one for each user, but this is the next step)

Here is the description of the flow, simply move from soucedir to anotherdir:

1 TRIGGER File Observer: /storage/emulated/0/SOURCEDIR on events Unwritable file closed
2 ACTION Init Variable File List: files to /storage/emulated/0/SOURCEDIR/*
3 EXPRESSION isEmpty(files) (IF FALSE)
4 ACTION: Set Flow State: DISABLED
5 ACTION: Move Files to ANOTHERDIR
6 ACTION: sleep 5s
7 ACTION: Set Flow State: ENABLED

It works but I have some question:
1 which is the better trigger to use to check if there is a new file downloaded?
2 and 3 maybe are redundant, but I copied from a previous flow, to avoid error of empty directories
5 , 6 and 7 are made because if I don't, the flow goes in a loop and I don't know why.

Thank you for now!

User avatar
Bingwu
Posts: 114
Joined: 26 Feb 2016 10:26

Re: Help on the better way to copy/move files

Post by Bingwu » 22 Jan 2018 09:56

Hello!

I was dealing with the same problem some time ago because I wanted to change the data structure on my devices. (unravel)
http://automagic4android.com/forum/viewtopic.php?t=6937

Basically, I also use the trigger "File observer", but with the event type "Modify", "Metadata changed", "File moved to" and "Subfile created".

But I realized very quickly that this does not always make sense.
With fast and many file changes, as for example with the admission of continuous shots (camera) or downloads with the Browser this did not always work perfectly.
This is not only due to the trigger, but the entire flow with the move process.

For these occasions, I'll use the trigger "App Task Ended" so the files will not be moved until the app is closed.

Then I proceed as follows (very simplified):
Action: Init Variable File List
Condition: Expression -> length(varfrominitvariablefilelist) > 0
(Expression: yes) Action : Move Files

Of course, this means that the flow will always fire when I close the app and use the "App Task Ended" trigger.
But I have not been able to determine disadvantages. (No increased battery consumption ...)

I hope my gibberish is a bit understandable and the translation of the German names of the trigger/conditions/actions is correct.

Regards
Peter

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

Re: Help on the better way to copy/move files

Post by wfrcrd » 22 Jan 2018 14:28

Thank you , I appreciated!

Sure I think it's better "app task ended" than the "sleep action"

(another step forward)

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

Re: Help on the better way to copy/move files

Post by Desmanto » 22 Jan 2018 15:33

4 (disable flow) and 7 (enable flow) are not needed. You can simply protect your flow by changing the AEP to Skip. And add a sleep for at least 500 ms to 1 second. This will ensure the trigger doesn't get triggered anymore by the action inside the same flow. More explanation about why should user AEP - Skip at my other thread, FEP & AES.

But yeah, the better trigger here is the App Task Ended. It won't drain much battery, since it only executed for a moment after you close the app. The app you have opened probably use more battery than the flow. Besides, it will split directly split the app branching, so whatsapp branch will only get triggered by whatsapp trigger, etc.
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: Help on the better way to copy/move files

Post by wfrcrd » 24 Jan 2018 09:28

Thank you Desmanto.
The aspect that I'd like to investigate most is the trigger,
the proper one I think should be the " Subfile created" (a new file or subdirectory was created under the monitored directory),
but to me (kk 4.4.2) don't work.
On the contrary the "unwritable file closed" trigger start even when it's not needed.

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

Re: Help on the better way to copy/move files

Post by Desmanto » 24 Jan 2018 12:36

From my previous quick test, each app behaves differently. Some create the app, some create temporary file and rename it after finish writing.
You want to make sure you only move the files after it has finished written. That's the main problem i haven't found out which one is the correct behaviour.

Have to log the behaviour and see how each app behave when creating the file. Chrome end the file download with Unwritable file closed too.
But MiXplorer trigger the event too frequently when browsing around the file, (as it queries for the folder size).
Let's see if I can have some mood to do the full test and check the behaviour. Need quite a lot setup and compare the result later. (and even more time to document it)
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: Help on the better way to copy/move files

Post by wfrcrd » 24 Jan 2018 16:18

My problem is that the flow is triggered while I'm open a file browser.

Thanks a lot!

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

Re: Help on the better way to copy/move files

Post by Desmanto » 24 Jan 2018 17:00

So it seems we have the same problem. Maybe we should exclude the execution by adding a check if the file browser is running, then do nothing.
The flow can be triggered, but it won't branch to the main logic.

Or we can use app task started, to disable the file observer flow when file browser is running; enable it back after closed.
Seems it is better to use the app task ended directly for the app we want.
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: Help on the better way to copy/move files

Post by wfrcrd » 24 Jan 2018 17:22

But this way could be tricky because if a new file comes while the file browser is already opened for other reasons
the action would not performed anymore, and this is bad.

I don't understand why the "create file" trigger dont' work: even if there is a temp file and than this file is renamed , or everything ..
a new file should be created!
If automagic could catch it , we could manage the situation easily, and (maybe I'm wrong) but I don't think that other apps (file browsers for example)
are creating new files on those directories.

Another question: there is the possibility to check with automagic the properties of the files?
( as I said in the first post I'd like to select files created from different whatsapp users , for example)

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

Re: Help on the better way to copy/move files

Post by Desmanto » 25 Jan 2018 13:57

Yeah, that's it. If the app can create file in background, it will missed when File browser is foreground.

When creating a new text file in Mixplorer, the sequence of creation from pressing new file until OK to create New File.txt, are as follow :
Subfile created 256
File Opened 32
Writeable file closed 8
Modify 2
File Opened 32
Writeable file closed 8

So even though i don't write anything inside, I don't know why there is modify event there. Can't use event 8, as it happen twice. Chrome also exhibit similar behaviour. A lot of events happen just for single operation.

As for file properties, what properties you wanna check? Automagic built-in Init file info seems to check for basic info, such as type, exists, size and last modified. To get much more info, you have to use Execute command (no root), ls or stat (probably need busybox)

Code: Select all

ls -l /sdcard/download/test.txt
or

Code: Select all

stat /sdcard/download/test.txt
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.

Post Reply