Skip to content

Instantly share code, notes, and snippets.

@CemraJC
Created October 23, 2015 04:53
Show Gist options
  • Save CemraJC/24fe9037a13908ab2ec0 to your computer and use it in GitHub Desktop.
Save CemraJC/24fe9037a13908ab2ec0 to your computer and use it in GitHub Desktop.
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
@CemraJC
Copy link
Author

CemraJC commented Oct 23, 2015

This is for recursively deleting stupid windows directories and their char limit of 255.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment