Rename/move multiple files script

Post your questions and help other users.

Moderator: Martin

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

Rename/move multiple files script

Post by wfrcrd » 20 Mar 2019 17:31

Here I am again, struggling against my huge programming limitation.
I need a simple script to use it in a NOT triggered flow ( I need to use it manually or executed by another flow),
to move and rename multiple FILES form directory A to directory B , and adding the suffix MOVED to their original names.

I'm trying to init Variable File List but then i'm not able to use the content of that variable :-(
If someone has some time to waist, thank you.

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

Re: Rename/move multiple files script

Post by Desmanto » 21 Mar 2019 10:24

The solution still using Init variable file list, to get the file list in the folder source. But we can't use action move files directly, since for multiple files, we have to mention a directory, which mean the source file name and destination file name will be the same. To make it different in each individual files and without looping action move files, we can simply use execute command, mv. (no root). We need to loop the list first in script, creating the lines of command before passing to execute command.

Code: Select all

line = newList();
target = "/storage/emulated/0/data/";
for(i in files)
  addElement(line, "mv '" + i + "' '" + replaceAll(i, "/.*/(.*)(\\..*)", "{target}$1_MOVED$2'") );
line store every command to move the file. Target is the path of destination. The loop add all element and its renamed version to the line. The renamed name is found by using replaceAll regex, added with _MOVED before the extention.

After this script, add Execute command and use
{line,listformat}
in the command field.
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: Rename/move multiple files script

Post by wfrcrd » 22 Mar 2019 11:28

Thank you thank you thank you Desmanto!

It works perfectly, the only thing to say is that , to me,
if the target directory is on the external SD I need to perform an "execute root command"
instead of a simple "execute command" due to a "permission denied" error.

Thank you really a lot!

Post Reply