Skip to content

Instantly share code, notes, and snippets.

@FlyTechVideos
Created January 13, 2023 18:37
Show Gist options
  • Save FlyTechVideos/6049ad219b28755b1121a75c49721277 to your computer and use it in GitHub Desktop.
Save FlyTechVideos/6049ad219b28755b1121a75c49721277 to your computer and use it in GitHub Desktop.
For use with WSL. Generates all reserved Windows file names (files and folders), zips them, then deletes the intermediary files.
#!/bin/bash
mkdir illegal_files # no -p flag, we don't want to overwrite/delete actual data
cd illegal_files
mkdir -p folders
mkdir -p files
mkdir -p files_with_extension
ILLEGAL_NAMES="CON PRN AUX NUL \
COM1 COM2 COM3 COM4 COM5 COM6 COM7 COM8 COM9 \
LPT1 LPT2 LPT3 LPT4 LPT5 LPT6 LPT7 LPT8 LPT9 "
for NAME in $ILLEGAL_NAMES
do
mkdir "./folders/$NAME"
echo "I am inside the $NAME folder now." > "./folders/$NAME/file.txt"
echo "I have just created $NAME." > "./files/$NAME"
echo "I have just created $NAME.txt." > "./files_with_extension/$NAME.txt"
done
zip -m illegal_files.zip -r *
mv illegal_files.zip ..
cd ..
rm -rf illegal_files
@MrBeastYoutube
Copy link

Nice

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