37 lines
811 B
Bash
37 lines
811 B
Bash
|
#!/bin/bash
|
||
|
|
||
|
# Path to the folder containing files
|
||
|
folder_path="$1"
|
||
|
|
||
|
# Path to the file containing the list of filenames
|
||
|
list_file="$2"
|
||
|
|
||
|
# Check if the folder exists
|
||
|
if [ ! -d "$folder_path" ]; then
|
||
|
echo "Folder does not exist: $folder_path"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# Check if the list file exists
|
||
|
if [ ! -f "$list_file" ]; then
|
||
|
echo "List file does not exist: $list_file"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# Loop through the files in the folder
|
||
|
for file_in_folder in "$folder_path"/*; do
|
||
|
# Check if the current file is a regular file
|
||
|
if [ -f "$file_in_folder" ]; then
|
||
|
# Get the filename without the path
|
||
|
filename=$(basename "$file_in_folder")
|
||
|
|
||
|
# Check if the filename is not in the list
|
||
|
if ! grep -qFx "$filename" "$list_file"; then
|
||
|
echo "Deleting: $file_in_folder"
|
||
|
rm "$file_in_folder"
|
||
|
fi
|
||
|
fi
|
||
|
done
|
||
|
|
||
|
|