Help with keep the most recent back up file

Hi, I want to search all the files inside "path" folder, with keywords from keyword_search for a case-insensitive partial match. If there are multiple files with the same keyword, only keep the most recent one, delete the older files.

keyword_search = ["foldersync", "novabackup", "adguard", "MacroDroid", "MiXplorer", "nclient", "T Swipe Pro"]
path = "/storage/emulated/0/Download/Back Up"

Here is how I want it to function:
1. Search for files with keyword, "foldersync" within the folder path "/storage/emulated/0/Download/Back Up"
2. If multiple files found with that keyword (partial match, case-insensitive), then only keep the most recent one.
3. Then search for the next keyword, "novabackup" then only keep the most recent one.
4. etc.

Is Macrodroid capable of doing this? I'd appreciate any ideas, thanks!
 
With a shell script it's possible
Thanks for the idea, just wondering what's the level of difficulty for someone with no shell script experience to come up with the script? Are there plugins that can help me do this that you're aware of?

Is the script from this link what you are referring to?
 

Dev777

Active member
Here is a script with bash. Lists the files containing the keywords, excludes the latest one and deletes them.
Edit the keywords in the keywords variable. Backup your folder first before trying it out
 

Attachments

  • Delete_old_files.macro
    2.2 KB · Views: 3
Here is a script with bash. Lists the files containing the keywords, excludes the latest one and deletes them.
Edit the keywords in the keywords variable. Backup your folder first before trying it out
Is this how I should define the keywords? Thanks!
keywords=([lv="foldersync" "novabackup" "adguard" "MacroDroid" "MiXplorer" "nclient" "T Swipe Pro"])
 
No just edit this.
It seems like it's detecting older files, but not deleting them. The keywords are already correct, am I doing anything wrong on my end? Here is the output:

rm: 2024-03-22_16-26.novabackup: No such file or directoryrm: 2024-03-22_16-24.novabackup: No such file or directoryrm: 2024-03-20_17-37.novabackup (1): No such file or directoryrm:
T Swipe Pro Gestures Backup 20240322162615.bak: No such file or directoryrm:
T Swipe Pro Gestures Backup 20240322162144.bak: No such file or directoryrm:
T Swipe Pro Gestures Backup 20240322162041.bak: No such file or directoryrm:
T Swipe Pro Gestures Backup 20240321235457.bak: No such file or directoryrm:
T Swipe Pro Gestures Backup 20240321235209.bak: No such file or directoryrm:
T Swipe Pro Gestures Backup 20240321235032.bak: No such file or directoryrm:
T Swipe Pro Gestures Backup 20240320175515.bak: No such file or directory

Screenshot_2024-03-23-21-36-27-93_07f20907771ad09ffa2dcbecf65bb740.jpg
 

Attachments

  • Delete_old_files_output.macro
    2.9 KB · Views: 1
Top