Created
October 23, 2015 04:53
-
-
Save CemraJC/24fe9037a13908ab2ec0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd "$1" | |
# Make sure they're confident that this is the correct directory | |
printf "\nAre you sure you want to completely wreck directory '%s'?\n" "$(pwd)" | |
prompt=b | |
until [[ "$prompt" =~ (yes|no) ]]; do | |
read -p "(Yes / No): " prompt | |
done | |
if [[ "$prompt" =~ no ]]; then | |
exit 0; | |
fi | |
# Now wreck the directory | |
wreck(){ | |
# Initialize Variables | |
local i=0 | |
local g=true | |
local IFS=$'\n' | |
# Until we find no more directories... | |
until [[ $g = false ]]; do | |
# Loop through all the files and directories in CWD | |
for c in $(ls); do | |
# If it is a directory... | |
if [[ -d $c && ! $(rm -rf $c > /dev/null) ]]; then | |
# Loop through *its* files and directories | |
for a in $(ls "$c"); do | |
i=$(expr $i + 1) # Keep track of how many we've done | |
# If it is a file... | |
if [[ -e $a ]]; then | |
rm -rf $a # Delete it | |
else | |
mv "$c/$a" "dir_$i" # Move it to the top | |
# directory under a new name | |
fi | |
done | |
# Finally, Remove the directory | |
rm -rf $c | |
elif [[ -e $c ]]; then | |
rm -rf $c # If it's a file, delete it | |
fi | |
done | |
if [[ ! $(ls) ]]; then | |
echo "Done!" | |
g=false | |
fi | |
done | |
} | |
wreck "$1" | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is for recursively deleting stupid windows directories and their char limit of 255.