remove also

main
Federico Poni 9 months ago
parent aa71900fce
commit b47249772f

@ -8,9 +8,11 @@ third="black"
background="white"
n_colors_dither="3"
footer=""
removeHtml=false
removeAll=false
# Parse command line options
while getopts ":f:1:2:3:d:b:foot" opt; do
while getopts ":f:1:2:3:d:b:F:rR" opt; do
case ${opt} in
f )
main_folder="$OPTARG"
@ -30,9 +32,16 @@ while getopts ":f:1:2:3:d:b:foot" opt; do
b )
background="$OPTARG"
;;
foot )
F )
footer="$OPTARG"
;;
r )
removeHtml=true
;;
R )
removeAll=true
;;
\? )
echo "Invalid option: $OPTARG" 1>&2
exit 1
@ -351,26 +360,79 @@ compress_and_generate_links() {
</body></html>" >> "$index_file"
}
# Function to iterate through all subfolders excluding "compressed"
# function to iterate through all subfolders
function iterate_subfolders() {
local folder="$1"
# Loop through each item in the folder
for item in "$folder"/*; do
# Check if the item is a directory
if [ -d "$item" ] && [ ! "$(basename "$item")" == "compressed" ] && [ ! "$(basename "$item")" == "*" ]; then
compress_and_generate_links "$item"
iterate_subfolders "$item"
echo "$item"
fi
done
if $removeHtml; then
# Loop through each item in the folder
for item in "$folder"/*; do
if [ -d "$item" ] && [ ! "$(basename "$item")" == "*" ]; then
iterate_subfolders "$item";
echo "$item";
elif [ "$(basename "$item")" == "index.html" ]; then
rm "$item";
fi
done
elif $removeAll; then
# Loop through each item in the folder
for item in "$folder"/*; do
# Check if the item is a directory
if [ -d "$item" ] && [ ! "$(basename "$item")" == "*" ]; then
if [ "$(basename "$item")" == "compressed" ]; then
echo $item;
rm -r "$item"
else
iterate_subfolders "$item"
echo "$item"
fi
elif [ "$(basename "$item")" == "index.html" ]; then
rm "$item"
fi
done
else
# Loop through each item in the folder
for item in "$folder"/*; do
# Check if the item is a directory
if [ -d "$item" ] && [ ! "$(basename "$item")" == "compressed" ] && [ ! "$(basename "$item")" == "*" ]; then
compress_and_generate_links "$item"
iterate_subfolders "$item"
echo "$item"
fi
done
fi
}
compress_and_generate_links "$main_folder"
# Start iterating from the main folder
iterate_subfolders $main_folder
# check if the command is supposed to delete stuff or generate stuff
if $removeHtml; then
rm 'index.html'
# Start iterating from the main folder
iterate_subfolders $main_folder
echo "HTML files deleted for each subfolder."
elif $removeAll; then
rm $main_folder/'index.html'
rm -r $main_folder/compressed
# Start iterating from the main folder
iterate_subfolders $main_folder
echo "HTML and compressed files deleted for each subfolder."
else
compress_and_generate_links "$main_folder"
# Start iterating from the main folder
iterate_subfolders $main_folder
echo "HTML files created for each subfolder."
fi
echo "HTML files created for each subfolder."
Loading…
Cancel
Save