Sync directory script

Post your questions and help other users.

Moderator: Martin

Post Reply
OsunSeyi
Posts: 6
Joined: 17 Dec 2019 17:27

Sync directory script

Post by OsunSeyi » 17 Dec 2019 23:18

Hi,
unfortunately I didn't found an app to mirror several directories from the internal storage to the sdcard (what is no problem for several clouds like 'foldersync' or 'dropsync'). Best choyce seems to be 'Auto Transfer'. This app copies all changed or new files, but it won't delete files from the target which are deleted on the source-directory.

Of cause, I know it's possible to create something nice with automagic, perhaps there is an easy solution?

At the moment I try to compare directories:

Code: Select all

{source_list} contains:

[.ttxfolder, Apk, Applications, Automagic, Kalender, Kontakte, READ-Dropsync.txt, READ-Restore.txt, Timesheet]

{target_list} contains:

[.ttxfolder, Apk, Applications, Automagic, Kalender, Kontakte, READ-Backups.txt, READ-Dropsync.txt, Test, Timesheet]

Now I would like to extract the Items in the target, which are not in the source for deleting, in this excemple 'Test':

items_to_delete = removeAllElementValues(target_list,source_list);

{items_to_delete} contains:

[.ttxfolder, Apk, Applications, Automagic, Kalender, Kontakte, READ-Backups.txt, READ-Dropsync.txt, Test, Timesheet]

...but it should contain only 'Test' !?
So what I'm doing wrong here?
Btw.. it's so absolute hard typing code on a handset...

User avatar
jassing
Posts: 94
Joined: 16 Jul 2017 01:42
Location: SF Bay Area

Re: Sync directory script

Post by jassing » 18 Dec 2019 11:58

Always good to post actual code/flow.

Code: Select all

source_list = newList('.ttxfolder','Apk','Applications','Automagic','Kalender','Kontakte','READ-Dropsync.txt','READ-Restore.txt','Timesheet') ;
target_list = newList('.ttxfolder','Apk','Applications','Automagic','Kalender','Kontakte','READ-Backups.txt','READ-Dropsync.txt','Test','Timesheet') ;

removeAllElementValues(target_list,source_list);
target_list contains [READ-Backups.txt, Test]

OsunSeyi
Posts: 6
Joined: 17 Dec 2019 17:27

Re: Sync directory script

Post by OsunSeyi » 18 Dec 2019 21:58

http://automagic4android.com/flow.php?i ... d01df0f049

Here the flow!
I modified the strings, but still the same result:

Code: Select all

source_files:
'.ttxfolder','Apk','Applications','Automagic','Kalender','Kontakte','READ-Dropsync.txt','READ-Restore.txt','Timesheet'

source_list:
['.ttxfolder','Apk','Applications','Automagic','Kalender','Kontakte','READ-Dropsync.txt','READ-Restore.txt','Timesheet']

~~~~~~~~~~~~~~~~~~~
target_files:
'.ttxfolder','Apk','Applications','Automagic','Kalender','Kontakte','READ-Backups.txt','READ-Dropsync.txt','Test','Timesheet'

target_list:
['.ttxfolder','Apk','Applications','Automagic','Kalender','Kontakte','READ-Backups.txt','READ-Dropsync.txt','Test','Timesheet']

~~~~~~~~~~~~~~~~~~~~
elements_to_delete = removeAllElementValues(target_list,source_list);

elements_to_delete:
['.ttxfolder','Apk','Applications','Automagic','Kalender','Kontakte','READ-Backups.txt','READ-Dropsync.txt','Test','Timesheet']

anuraag
Posts: 371
Joined: 24 Jan 2015 02:06

Re: Sync directory script

Post by anuraag » 18 Dec 2019 23:22

This script you used isn't the way to generate a newList.

Code: Select all

source_files = replaceAll(source_files, '\\[', "'");
source_files = replaceAll(source_files, '\\]', "'");
source_files = replaceAll(source_files, source, '');
source_files = replaceAll(source_files, ', ', "','");
source_files = replaceAll(source_files, '/', '');
source_list  = newList(source_files);
Replace above code with

Code: Select all

source_list = newList();
for (i in source_files)
{
	addElement(source_list, replace(i, source, ""))
}
Do similar for target_list.

User avatar
jassing
Posts: 94
Joined: 16 Jul 2017 01:42
Location: SF Bay Area

Re: Sync directory script

Post by jassing » 19 Dec 2019 01:36

As pointed out, you're not using lists right. See my code as an alternate example

OsunSeyi
Posts: 6
Joined: 17 Dec 2019 17:27

Re: Sync directory script

Post by OsunSeyi » 19 Dec 2019 08:09

Thank's a lot, I. think I got it now.
For testing the output, I'm using this:

http://automagic4android.com/flow.php?i ... bfb214ffe4

Is there a more easy way creating flows and testing the output of each step? I find it very hard typing on the smartphone, and testing what I'm writing on the fly!
I'm using Minuum, which is nice.

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

Re: Sync directory script

Post by Desmanto » 21 Dec 2019 16:30

If typing on smartphone is too difficult, you can mirror your phone to the PC and type from there. Use scrcpy : viewtopic.php?f=5&t=8394&p=26412#p26412
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.

OsunSeyi
Posts: 6
Joined: 17 Dec 2019 17:27

Re: Sync directory script

Post by OsunSeyi » 21 Dec 2019 17:55

8-)
Thank's a lot & happy xmas

User avatar
jassing
Posts: 94
Joined: 16 Jul 2017 01:42
Location: SF Bay Area

Re: Sync directory script

Post by jassing » 22 Dec 2019 04:21

What about using TeamViewer?

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

Re: Sync directory script

Post by Desmanto » 22 Dec 2019 10:11

I never use teamviewer. But I know it is similar to VNC. And VNC is quite laggy if android is the server, it also require root (AFAIK). The control can't be passed properly. While scrcpy only use adb, can be done wirelessly (after redirect the port or using root), have integrated shortcut for input and you can customize a lot of the feature. Also it can be done offline, without any internet or wifi (if you use USB cable only). Framerate is also much better and smoother.
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