Back to Discover
🏏 code_translation_bash_to_python
Translate Bash code to Python, provided under the Apache 2.0 license
System Message
Format the following prompt, don't add or change the text, just format it with new lines as necessary
Prompt
Translate the following Bash code snippet to Python:
#!/bin/bash
# Ask for the folder name
echo "Enter the folder name: "
read folder_name
# Check if the folder exists
if [ ! -d "$folder_name" ]; then
echo "Folder does not exist."
exit 1
fi
# Get the list of files in the folder
files=( "$folder_name"/* )
# Rename each file by prepending "draft" to the file name
for file in "${files[@]}"; do
new_file_name="draft_$(basename "$file")"
mv "$file" "$new_file_name"
done
echo "Files renamed successfully."