Add All existing
This commit is contained in:
51
list_folder_empty
Executable file
51
list_folder_empty
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Function to list files in a directory
|
||||
list_contents() {
|
||||
local dir="$1"
|
||||
local result=()
|
||||
|
||||
# Check if the directory contains files or subdirectories
|
||||
local has_file=false
|
||||
local has_folder=false
|
||||
|
||||
# Loop through the directory contents
|
||||
for item in "$dir"/*; do
|
||||
if [ -f "$item" ]; then
|
||||
# If it's a file, get its extension and add it to the result
|
||||
ext="${item##*.}"
|
||||
result+=("$ext")
|
||||
has_file=true
|
||||
elif [ -d "$item" ]; then
|
||||
has_folder=true
|
||||
fi
|
||||
done
|
||||
|
||||
# If files are found, return their extensions
|
||||
if [ "$has_file" = true ]; then
|
||||
echo "$(printf "%s, " "${result[@]}" | sed 's/, $//')"
|
||||
elif [ "$has_folder" = true ]; then
|
||||
echo "folder"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to recursively list non-empty directories
|
||||
list_non_empty_directories() {
|
||||
local base_dir="$1"
|
||||
|
||||
# Loop through the directories in the base directory
|
||||
for dir in "$base_dir"/*; do
|
||||
if [ -d "$dir" ]; then
|
||||
# List contents of the directory
|
||||
contents=$(list_contents "$dir")
|
||||
if [ -n "$contents" ]; then
|
||||
echo "$(basename "$dir") ($contents)"
|
||||
fi
|
||||
# Recursively check subdirectories
|
||||
list_non_empty_directories "$dir"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Start listing from the current directory
|
||||
list_non_empty_directories "."
|
||||
Reference in New Issue
Block a user