💾 Archived View for d.moonfire.us › blog › 2012 › 08 › 13 › getting-number-of-different-files captured on 2022-06-03 at 23:32:21. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2022-04-28)
-=-=-=-=-=-=-
rm -f /tmp/convert-status-$
for dir in “$@” do # Ignore non-directories. if [ ! -d “$dir” ] then # Create a generic placeholder for all non-directories. echo “-FILES-” >> /tmp/convert-status-$ continue fi
# Include the directory name. echo "$dir" >> /tmp/convert-status-$
done
m=$(awk ' { if ( length > L ) }END' /tmp/convert-status-$)
printf “%-$s Count MP4 MKV AVI MOV MPG\n” printf “%-$s —– —- —- —- —- —-\n”
max=0 max_mkv=0 max_mp4=0 max_avi=0 max_mov=0 max_mpg=0
files=0 files_mkv=0 files_mp4=0 files_avi=0 files_mov=0 files_mpg=0
for dir in “$@” do # Ignore non-directories. if [ ! -d “$dir” ] then # If this is a file, we just add to the counters. case ${dir#*.} in “mp4”) files_mp4=$(expr $files_mp4 + 1);; “mkv”) files_mkv=$(expr $files_mkv + 1);; “avi”) files_avi=$(expr $files_avi + 1);; “mov”) files_mov=$(expr $files_mov + 1);; “mpg”) files_mpg=$(expr $files_mpg + 1);; *) continue;; esac
# Increment the general file counter. files=$(expr $files + 1) # Don't bother doing anything else. continue fi # Count the number of files of a given type inside that # directory. Since we are using `find`, this will recursively get # all the files inside subdirectories also. We don't care about # the file names, just how many we find. This does have a slight # bug if you have a .filename.extension file (which I use for # temporary files), but usually that is okay. mkv=$(find "$dir" -name "*.mkv" | wc -l) mp4=$(find "$dir" -name "*.mp4" | wc -l) avi=$(find "$dir" -name "*.avi" | wc -l) mov=$(find "$dir" -name "*.mov" | wc -l) mpg=$(find "$dir" -name "*.mpg" | wc -l) # Add up all the counts above so we have a "total files per # directory" variable. count=$(expr $mkv + $mp4 + $avi + $mov + $mpg) # Increment the grand totals for the bottom line. max_mp4=$(expr $max_mp4 + $mp4) max_mkv=$(expr $max_mkv + $mkv) max_avi=$(expr $max_avi + $avi) max_mov=$(expr $max_mov + $mov) max_mpg=$(expr $max_mpg + $mpg) max=$(expr $max + $count) # Write out a single record for everything, but only if we have # something. if [ $count -gt 0 ] then printf "%-${m}s %5d %4d %4d %4d %4d %4d\n" \ "$dir" \ $count $mp4 $mkv $avi $mov $mpg fi
done
if [ $files -gt 0 ] then printf “%-$s %5d %4d %4d %4d %4d %4d\n”
“-FILES-”
$files $files_mp4 $files_mkv $files_avi $files_mov $files_mpg fi
max=$(expr $max + $files) max_mp4=$(expr $max_mp4 + $files_mp4) max_mkv=$(expr $max_mkv + $files_mkv) max_avi=$(expr $max_avi + $files_avi) max_mov=$(expr $max_mov + $files_mov) max_mpg=$(expr $max_mpg + $files_mpg)
printf “%-$s —– —- —- —- —- —-\n” printf “%-$s %5d %4d %4d %4d %4d %4d\n”
“”
$max $max_mp4 $max_mkv $max_avi $max_mov $max_mpg
Categories:
Tags:
Below are various useful links within this site and to related sites (not all have been converted over to Gemini).
https://d.moonfire.us/blog/2012/08/13/getting-number-of-different-files/