2023-07-25 11:51:50 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-08-03 03:26:51 +00:00
|
|
|
#######################################
|
|
|
|
# Calculate the number of files in a directory.
|
|
|
|
# Call this function like this: num_files "${file_path}".
|
|
|
|
# Globals:
|
|
|
|
# None
|
|
|
|
# Arguments:
|
|
|
|
# $1: the directory path
|
|
|
|
# Returns:
|
|
|
|
# the number of files in the directory
|
|
|
|
#######################################
|
|
|
|
num_files() {
|
|
|
|
[[ $# -eq 1 ]] || return 1
|
|
|
|
local file_num
|
|
|
|
file_num=$(ls -l $1 | grep '^-' | wc -l)
|
|
|
|
echo $file_num
|
2023-07-25 11:51:50 +00:00
|
|
|
}
|