Trying to run a shell script to find out how many files are in a directory, but I'm stuck

Nonhocapito

New member
As the title says. As I am new to both Macrodroid and scripting in bash in general, no surprise I got stuck.

My purpose is to know how many files are in a folder and, if they're too many, delete the oldest ones.

To begin with, I am using a shell script that uses
"ls -m" followed by folder path.

(i previously complained this didn't work, but actually it does now, I needed to remove "root" from the script)

My next step would be to count the items in that comma-separated string... How to achieve this via script? Or should I transfer it into an array?

EDIT: I did manage to extract the number of commas via script. The only problem is that this number can only be saved to a string, and I cannot "count" it or compare it to another number....
 
Last edited:

Endercraft

Moderator (& bug finder :D)
The only problem is that this number can only be saved to a string, and I cannot "count" it or compare it to another number....
You can compare using another variable (integer), with a variable constraint (choose the integer variable, choose expression and enter the magic text “[strval=(your variable name)]”).
 

Nonhocapito

New member
You can compare using another variable (integer), with a variable constraint (choose the integer variable, choose expression and enter the magic text “[strval=(your variable name)]”).
You are saying MD can handle something like
Code:
If Integer > String
?

EDIT: When I tried to do what you say, and I clicked on the "+", the local string variable I got from the shell script was not listed.

But, once I entered the string name manually, it seems to have worked. Thanks!!
 
Last edited:
Top