Skip to content

Instantly share code, notes, and snippets.

@TooDumbForAName
Created March 25, 2020 10:59
Show Gist options
  • Save TooDumbForAName/a7cc05b1a14be1dc99d7ce943e42b2bb to your computer and use it in GitHub Desktop.
Save TooDumbForAName/a7cc05b1a14be1dc99d7ce943e42b2bb to your computer and use it in GitHub Desktop.
#!/bin/bash
#Common function
createpopulatedir () {
mkdir "$DIRECTORY"
printf "%s\n" "Copying contents from $PWD to $DIRECTORY."
cp -r . "$DIRECTORY"
printf "%s\n" "Copying complete!"
}
#Prompt user for target directory
printf "\033[97m%s\n" "Please enter the directory you wish to copy files to."
printf "\033[31m%s\n" "Warning! All pre-existing files in directory will be deleted!"
printf "\033[97m%s" "Directory: "
read DIRECTORY
if [ -d "$DIRECTORY" ]; then
printf "%s\n" "Directory exists, deleting!..."
rm -rf "$DIRECTORY"
printf "%s\n" "Recreating empty directory..."
createpopulatedir
elif [ ! -d "$DIRECTORY" ]; then
printf "%s\n" "Directory does not exist, creating..."
createpopulatedir
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment