Count number of files

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Count number of files Mon Jun 03, 2013 4:21 pm • by novajunior
Is there a way to count a certain number of files using its extension?

Example: If there is greater than 5 .txt files in the folder, then do something...
novajunior
 
Posts: 18
Joined: Thu May 30, 2013 2:38 am

Re: Count number of files Tue Jun 04, 2013 12:18 pm • by Mr_Noodle
Right now, you can only do a total count of files. To count specific types, you'll have to use a script.
Mr_Noodle
Site Admin
 
Posts: 11865
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Count number of files Tue Jun 04, 2013 1:21 pm • by a_freyer
This will allow you to run conditions on any file if there are "other" files of the same type. In the example below,

Code: Select all
if (all) of the following conditions are met for (the file or folder being processed):
     extension is CSV
     passes shell script (embedded script)
     ...

Do the following to the matched file or folder:
     send notification "there are 8 or more files in this folder with the extension " (extension)


Code: Select all
MAXCOUNT=8;
filename=$(basename "$1"); extension="${filename##*.}"
if [ "$(ls -1 $(dirname "$1")| grep -cE ".$extension$")" -gt "$MAXCOUNT" ]; then exit 0; else exit 1; fi
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Count number of files Tue Jun 04, 2013 2:30 pm • by novajunior
Thanks, thats great I will try that out
novajunior
 
Posts: 18
Joined: Thu May 30, 2013 2:38 am


Return to Support