Page 1 of 1
Rename/move multiple files script
Posted: 20 Mar 2019 17:31
by wfrcrd
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.
Re: Rename/move multiple files script
Posted: 21 Mar 2019 10:24
by Desmanto
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.
Re: Rename/move multiple files script
Posted: 22 Mar 2019 11:28
by wfrcrd
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!