gpt-4-0314· openai
Suzhen/CodeChat
Give me a short script to touch files in a directory recusively
- User
Give me a short script to touch files in a directory recusively
- Assistant
#!/bin/bash # Script to touch files in a directory recursively # Function to process a directory process_directory() { local dir_path="$1" for file_path in "$dir_path"/*; do if [ -d "$file_path" ]; then process_directory "$file_path" elif [ -f "$file_path" ]; then touch "$file_path" fi done } # Check if the directory is provided if [ -z "$1" ]; then echo "Usage: $0 <directory>" exit 1 fi # Check if the directory exists if [ ! -d "$1" ]; then echo "Error: Directory \"$1\" not found!" exit 1 fi # Start processing the directory process_directory "$1"To use the script, save it to a file (e.g. touch_files.sh) and run it with the target directory as an argument:
chmod +x touch_files.sh ./touch_files.sh /path/to/your/directory