Trigger "File Observer" without existing directory

Post your questions and help other users.

Moderator: Martin

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

Trigger "File Observer" without existing directory

Post by Bingwu » 07 Sep 2017 14:03

Hello!

Is it possible to monitor directories which do not exist? (Trigger "File Observer"?)
This may sound a little strange, so a brief explanation.

It bothers me that some apps store downloaded or created files in different places in the internal memory.
Therefore, I want to merge these files elsewhere in the internal memory and delete the "superfluous" app-directories.

My Utility-Flows for selectively moving files and deleting the source directory (when empty) work fine.
The problem is the trigger!

The procedure should look as follows:

1.: The app (whichever) is installed. -> Status: The directory to be monitored does not exist.
2.: The app will download/create a file. -> Status: The directory to be monitored is created by the app and contains the downloaded/created file.
3.: Trigger-Flow with trigger XXX ("File Observer"?)
3a.: The existing utility-flow for moving files is called. -> Status: The file has been moved to the target directory, the directory to be monitored exists and is empty.
3b.: The existing utility-flow for deleting the directory to be monitored is called. -> Status: The directory to be monitored does not exist.

However, the trigger "File Observer" does not appear if the directory to be monitored has been deleted (3b.), or if the directory was not created when the trigger was created. (1.)
Has anyone of you perhaps a solution for me?

Many thanks!
Peter
-----------------------------------------------------------------------------------
Hallo!

Ist es möglich Verzeichnisse zu überwachen welche nicht existieren? (Trigger "Datei Überwacher"?)
Das klingt vielleicht ein wenig seltsam, daher eine kurze Erläuterung.

Es stört mich, daß einige Apps heruntergeladene oder erstellte Dateien an den unterschiedlichsten Stellen des internen Speichers ablegen.
Daher will ich diese Dateien an anderer Stelle des internen Speichers zusammenführen und die "überflüssigen" App-Verzeichnisse löschen.

Meine Utility-Flows für das selektive Verschieben von Dateien und das Löschen des Ursprungsverzeichnisses (wenn leer) funktionieren.
Das Problem ist der Trigger!

Der Ablauf soll wie folgt aussehen:

1.: Die App (welche auch immer) ist installiert. -> Status: Das zu überwachende Verzeichnis ist nicht vorhanden.
2.: Mit der App wird eine Datei herunterladen/erstellt. -> Status: Das zu überwachende Verzeichnis wird durch die App angelegt und enthält die heruntergeladene/erstellte Datei.
3.: Trigger-Flow mit Trigger XXX ("Datei Überwacher"?)
3a.: Es wird der vorhandene Utility-Flow zum verschieben von Dateien aufgerufen. -> Status: Die Datei wurde in das Ziel-Verzeichnis verschoben, das zu überwachende Verzeichnis existiert und ist leer.
3b.: Es wird der vorhandene Utility-Flow zum Löschen des zu überwachenden Verzeichnisses aufgerufen. -> Status: Das zu überwachende Verzeichnis ist nicht vorhanden.

Der Trigger "Datei Überwacher" scheint jedoch nicht reagieren, wenn das zu überwachende Verzeichnis einmal gelöscht wurde (3b.), beziehungsweise wenn das Verzeichnis beim Erstellen des Triggers nicht existent war. (1.)
Hat von Euch vielleicht jemand einen Lösungsvorschlag für mich?

Vielen Dank!
Peter

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

Re: Trigger "File Observer" without existing directory

Post by Desmanto » 07 Sep 2017 15:18

Yes it is. You just remind the same file observer for rogue app. Sometimes we install too many apps to try it out and they leave a lot of corpse behind after uninstalled. I usually manually delete them, or just sort it based on modified date and trace one by one, delete manually. I am thinking about creating a flow which log only a certain amount of time after the app installed. But not in my priority list.

You can use Action Init Variable File List, /storage/emulate/0/* (or whatever your root sdcard folder), save it to a GloVar, example : global_files and check the Include changes only. Put this action in the trigger where the app is first installed. It will capture the whole SDcard folders/files list.

Then periodically (period timer) or just manually trigger after you have downloaded something thru the app, execute that Action Init Variable File List with the same option. It will log only changed folder/files (including automagic folder if you have it in root folder of sdcard). You can check the Include file attributes if you want more detail list. Now, remove the element which contain automagic or other known folder. Leaving out only the changed folder. You can then access the list and move them to your target directory.

Just remember that the app will continue to recreate the folder as long as you still use it. So, this will work only for the app which you have uninstalled afterward.
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.

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

Re: Trigger "File Observer" without existing directory

Post by Bingwu » 07 Sep 2017 16:41

Hello Desmanto, thanks for your reply!

I want to avoid a timer or manually triggering the flow(s). :-/
The file operations are also not the problem. (Utility-Flows)

I need a trigger that detects when a file is created/modified in a directory. This is the trigger "File Observer".

The problem is that the directory will be created. (does not currently exist)
The "File Observer" triggers, however, only to monitor directories that already exist.

Regards
Peter
---------------------------------------------------------------------------------------------------------------
Hallo Desmanto, danke für deine Antwort!

Einen Timer oder manuelles Auslösen des (der) Flows will ich vermeiden. :-/
Die Datei-Operationen sind auch nicht das Problem. (Utility-Flows)

Ich benötige einen Trigger der erkennt wenn eine Datei in einem Verzeichnis erstellt/geändert wird. Das ist der Trigger "Datei Überwacher".

Das Problem ist, daß das Verzeichnis erst erstellt werden wird. (aktuell nicht existiert)
Der Trigger "Datei Überwacher" scheint aber nur Verzeichnisse zu überwachen die bereits existieren.

Gruß
Peter

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

Re: Trigger "File Observer" without existing directory

Post by Desmanto » 07 Sep 2017 17:44

If you insist on using File Observer, it still can be done thru GloVar. You need 2 triggers. You can put them into 2 flows, or just parallel expression it into single flow. I will explain using 2 flows.

First create the GloVar global_files as new List. Then, create these 2 flows.

1. Trigger File Observer, check only Subfile created. Path : /storage/emulated/0
Action script :

Code: Select all

addElement(global_files, "{registered_path}\/{path}")
This flow will check for additional folder added, and saved it to GloVar.

2. Trigger File Observer, check only Subfile created. Path : {global_files,listformat,comma}
Action : move files, or just do whatever you want to do with the file. As your case is to move them to another folder, the source will be {registered_path}/{path}, target is /storage/emulated/0/target/{path}

The second flow will observe the folder created by the first flow, and move every additional file to your target folder.

After some time, global_files will be stacked up quickly. So make sure you reset the value using some other trigger or manually. Or if you want to delete the folder after moving, you can delete the folder and delete that element as well from GloVar, using removeElementValue(). So it is not monitored anymore by the second flow.

Edit : you may need to add if(isDirectory() to the trigger path, to make sure it is a folder, before adding it to GloVar.
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.

User avatar
Bluscre
Posts: 144
Joined: 31 Aug 2017 13:58
Location: Germany
Contact:

Re: Trigger "File Observer" without existing directory

Post by Bluscre » 07 Sep 2017 18:14

Also you should make sure you dont get duplicates in your list
Unofficial AutoMagic Telegram Group: http://t.me/automagic4android
Check out my other flows here: https://github.com/Bluscream/AutoMagicFlows or here.
Sent from my Lenovo TAB 2 A10-70L running Android 6.0.

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

Re: Trigger "File Observer" without existing directory

Post by Bingwu » 08 Sep 2017 12:31

Hello Demsanto!

Thank you for your suggestions!
Unfortunately the trigger "File Observer" does not work (with me) with content-changing variables.

greetings
Peter
----------------------------------------------------------------------------------------------------
Hallo Demsanto!

Vielen Dank für deine Vorschläge!
Leider funktioniert der Trigger "Datei Überwacher" (bei mir) nicht mit sich inhaltlich verändernden Variablen.

Gruß
Peter

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

Re: Trigger "File Observer" without existing directory

Post by Desmanto » 08 Sep 2017 14:09

What variable do you put at the File Observer? It should be global variable, as the variable need to pass across flow. And it must be in listformat comma, as the folder need to be separated by comma.
Try the first flow file observer and check manually the value of the global_files, is it storing the value passed from the flow 1.
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.

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

Re: Trigger "File Observer" without existing directory

Post by Bingwu » 08 Sep 2017 14:54

Hello Demanto!

The first trigger "File Observer" (and the script) normally generates the global variable (
  • "global_files") with the first directory level after "/storage/emulated/0".
    The second trigger "File Observer" with the path {global_files,listformat,comma} ("content-changing variables") does not trigger.

    I am surprised that the second trigger works with you and not with me!

    greetings
    Peter
    ------------------------------------------------------------------------------------------------------------------------------------------------
    Hallo Demanto!

    Der erste Trigger "Datei Überwacher" (und das Script) generiert ganz normal die globale Variable ([Liste] "global_files") mit der ersten Verzeichnisebene nach "/storage/emulated/0".
    Der zweite Trigger "Datei Überwacher" mit dem Pfad {global_files,listformat,comma} ("inhaltlich verändernden Variablen") löst nicht aus.

    Es wundert mich, daß der zweite Trigger bei dir funktioniert und bei mir nicht!

    Gruß
    Peter
    ------------------------------------------------------------------------------------------------------------------------------------------------
    PS: "And it must be in listformat comma, ...": http://automagic4android.com/forum/view ... 726#p18726

User avatar
Bluscre
Posts: 144
Joined: 31 Aug 2017 13:58
Location: Germany
Contact:

Re: Trigger "File Observer" without existing directory

Post by Bluscre » 08 Sep 2017 15:07

Can you share the flow so we have it easier to help you?

------------

Können du ihren flug teilen damit ich ihnen helfen kann?
Unofficial AutoMagic Telegram Group: http://t.me/automagic4android
Check out my other flows here: https://github.com/Bluscream/AutoMagicFlows or here.
Sent from my Lenovo TAB 2 A10-70L running Android 6.0.

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

Re: Trigger "File Observer" without existing directory

Post by Bingwu » 08 Sep 2017 15:19

flow_group_File_Observer_20170908_171646.xml
(3.81 KiB) Downloaded 410 times

Post Reply