Hello!
I need help moving files (Action: "Move Files").
I want to move all the files of a directory (except one specific file) to another directory.
In principle, therefore:
Source Files -> /storage/emulated/0/source/*.* (Different file names, file name lengths, file extensions)
Target -> /storage/emulated/0/target
Exception: The file "backup.prefs" must not be moved.
My knowledge of regular expressions is, unfortunately, too limited. It would be great if someone could show me a solution.
Thank you!
Peter
------------------------------------------------------------------------------------------------------------------------
Hallo!
Ich brauche Hilfe beim Verschieben von Dateien (Aktion: "Dateien verschieben").
Ich möchte alle Dateien eines Verzeichnisses (ausser einer bestimmten Datei) in ein anderes Verzeichnis verschieben.
Grundsätzlich also:
Quelldateien -> /storage/emulated/0/quelle/*.* (unterschiedlichste Dateinamen, Dateinamenlängen, Dateierweiterungen)
Ziel -> /storage/emulated/0/ziel
Ausnahme: Die Datei "backup.prefs" darf nicht verschoben werden.
Mein Wissen über reguläre Ausdrücke ist leider zu begrenzt. Es wäre grossartig, wenn mir jemand einen Lösungsweg zeigen könnte
Danke!
Peter
Move all files - except ...
Moderator: Martin
Re: Move all files - except ...
Created a quick flow. You need to edit source and target folders.
- Attachments
-
- flow_Move_files_with_exception_20170831_191632.xml
- (2.16 KiB) Downloaded 1017 times
Re: Move all files - except ...
Hello anuraag!
I thank you for your efforts and the quick help!
Excellent! Create a list of existing files and then remove the single file.
And ...
I'm so stupid! The same thing I do when transferring flows.
Best regards
Peter
I thank you for your efforts and the quick help!
Excellent! Create a list of existing files and then remove the single file.

And ...

I'm so stupid! The same thing I do when transferring flows.
Best regards
Peter
Re: Move all files - except ...
Do the flow/script works? I tried, and it will give error because of the "[" (left bracket)
Putting list variable at the source seems to have trouble with the bracket.
I know it can be done with single line script as
But it doesn't work. Strange. If I copy the list manually and create the variable list from it in another place, that single line can remove the backup.prefs.
Seems that {files} from init variable file list is not a real list. copyList() to another list also doesn't work, can't remove using removeElementValue().
So next level is to remove it using index,
It works fine. indexOfElement() will get the index of the backup.prefs. removeElement() will remove that index.
However, this still give problem with the bracket. So we need to remove that bracket, by turning that list into string, separated by comma. Since the option specify multiple files can be separated by comma. Adding the join()
This will remove the backup.prefs and join the list {files} to a single string that can be passed to the source.
However, another problem arise (again). The same problem with SSID handling, where comma in the SSID name will destroy the logic of the flow. Same thing happens here, as it is using the same comma splitting for multiple items.
If your file name has comma inside, the flow will be error. So we have to double quote each of the file name. Using "{files}" won't work, as it is different with SSID solution, the {files} is a list.
And remember, it should be double quote, as file name can have single quote also (but not double quote).
Considering all above, there is no easy way by just 2 line of script. We have to double quote each element, so it is easier to loop the list. I just take the same script structure from anuraag, modify it a bit.
This should work, even you have comma in your file name.
Putting list variable at the source seems to have trouble with the bracket.
I know it can be done with single line script as
Code: Select all
removeElementValue(files, "/storage/emulated/0/source/backup.prefs")
Seems that {files} from init variable file list is not a real list. copyList() to another list also doesn't work, can't remove using removeElementValue().
So next level is to remove it using index,
Code: Select all
removeElement(files, indexOfElement(files, "/storage/emulated/0/source/backup.prefs"));
However, this still give problem with the bracket. So we need to remove that bracket, by turning that list into string, separated by comma. Since the option specify multiple files can be separated by comma. Adding the join()
Code: Select all
removeElement(files, indexOfElement(files, "/storage/emulated/0/source/backup.prefs"));
files = join(files,",")
However, another problem arise (again). The same problem with SSID handling, where comma in the SSID name will destroy the logic of the flow. Same thing happens here, as it is using the same comma splitting for multiple items.
If your file name has comma inside, the flow will be error. So we have to double quote each of the file name. Using "{files}" won't work, as it is different with SSID solution, the {files} is a list.
And remember, it should be double quote, as file name can have single quote also (but not double quote).
Considering all above, there is no easy way by just 2 line of script. We have to double quote each element, so it is easier to loop the list. I just take the same script structure from anuraag, modify it a bit.
Code: Select all
files_move = newList();
for(i in [0 to length(files)-1])
{
if(!contains(files[i], "backup.prefs"))
addElement(files_move, "\"{files[i]}\"")
}
files_move = join(files_move,",")
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.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: Move all files - except ...
@Desmanto
You are correct. I haven't tested flow. Thanks for checking.
You are correct. I haven't tested flow. Thanks for checking.
Re: Move all files - except ...
Hello!
I have changed (Action "Move Files") {files_move} to {files_move,listformat,comma}.
Is working!
greetings
Peter
I have changed (Action "Move Files") {files_move} to {files_move,listformat,comma}.
Is working!
greetings
Peter
Re: Move all files - except ...
Another enlightment
Thanks for the info, never knew we can use that listformat. I probably should reread the documentation.
When using list format, any name with special character or single quote, will be automagically double quoted. So no problem with the special character anymore.
So we only need the single line script
Then use {files,listformat,comma} at the Action Move Files.

When using list format, any name with special character or single quote, will be automagically double quoted. So no problem with the special character anymore.
So we only need the single line script
Code: Select all
removeElement(files, indexOfElement(files, "/storage/emulated/0/source/backup.prefs"));
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.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.