Ajout du thème autohébergement
This commit is contained in:
parent
b5c925e175
commit
2a7b056698
22 changed files with 1234 additions and 0 deletions
45
backend/rename_files.sh
Executable file
45
backend/rename_files.sh
Executable file
|
@ -0,0 +1,45 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Check if the required arguments are provided
|
||||
if [ "$#" -ne 3 ]; then
|
||||
echo "Usage: $0 <directory> <search_expression> <replace_expression>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Assign arguments to variables
|
||||
directory="$1"
|
||||
search_expr="$2"
|
||||
replace_expr="$3"
|
||||
|
||||
# Check if the directory exists
|
||||
if [ ! -d "$directory" ]; then
|
||||
echo "Error: Directory '$directory' does not exist."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Function to rename files
|
||||
rename_files() {
|
||||
local dir="$1"
|
||||
|
||||
# Loop through all files and directories in the current directory
|
||||
for item in "$dir"/*; do
|
||||
if [ -d "$item" ]; then
|
||||
# If it's a directory, recurse into it
|
||||
rename_files "$item"
|
||||
elif [ -f "$item" ]; then
|
||||
# If it's a file, rename it if it matches the search expression
|
||||
local filename=$(basename "$item")
|
||||
if [[ "$filename" == *"$search_expr"* ]]; then
|
||||
local new_filename="${filename//$search_expr/$replace_expr}"
|
||||
local new_path="${item%/*}/$new_filename"
|
||||
mv "$item" "$new_path"
|
||||
echo "Renamed: $item -> $new_path"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Start the renaming process
|
||||
echo "Starting renaming process in directory: $directory"
|
||||
rename_files "$directory"
|
||||
echo "Renaming process complete."
|
Loading…
Add table
Add a link
Reference in a new issue