Deleting files after a certain amount of time

matte

New member
I'm looking for an macro that deletes files older than X time But if the folder has only one file, don't do anything, is there something like this?
 

Dm114

Well-known member
I'm looking for an macro that deletes files older than X time But if the folder has only one file, don't do anything, is there something like this?
The best way would probably be via shell script. Users who know that better than I do will probably help you soon.
 

Dev777

Active member
Needs shell script.
This test macro deletes files older than 30 mins in the directory "/storage/emulated/0/testfolder"
If only one file exists it won't be deleted even if it's older than 30 mins.
Modify the folder and time to your liking
 

Attachments

  • TestDelete.macro
    1.7 KB · Views: 10

matte

New member
Needs shell script.
This test macro deletes files older than 30 mins in the directory "/storage/emulated/0/testfolder"
If only one file exists it won't be deleted even if it's older than 30 mins.
Modify the folder and time to your liking
The script seems to work but permission is denied by the helper

24-02-28 11:28:41 - shell command complete: File più vecchi di 10 minuti eliminati.find: .: Permission denied
24-02-28 11:28:41 - Outputting line to shell
24-02-28 11:28:41 - Outputting line to shell
24-02-28 11:28:41 - Received shell script request id=14 macro=Test script script=#!/bin/bash

folder_path="/storage/emulated/0/Obtaniun export"
threshold=10

# Conta il numero di file nella cartella
file_count=$(ls -1 "$folder_path" | wc -l)

# Verifica se ci sono almeno due file prima di procedere
if [ "$file_count" -gt 1 ]; then
# Trova i file più vecchi di 10 minuti e li elimina
find "$folder_path" -type f -mmin +$threshold -exec rm {} \;
echo "File più vecchi di $threshold minuti eliminati."
else
echo "La cartella contiene un solo file. Niente da fare."
fi
 

Dev777

Active member
MD helper has permissions?

adb shell pm grant com.arlosoft.macrodroid.helper android.permission.WRITE_SECURE_SETTINGS
 
Top