Created
May 18, 2025 00:02
-
-
Save kmcintyre/8e4d5866f04396be034e7aba47b68f62 to your computer and use it in GitHub Desktop.
Bash script to generate a test ZIP archive containing numerous 0-byte files with diverse extensions, organized into a single subfolder. Useful for testing MIME type detection or file explorer functionalities.
This file contains hidden or 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
| #!/bin/bash | |
| # Script to create a test zip file with various 0-byte files, | |
| # all placed within a single folder inside the zip. | |
| # --- Configuration --- | |
| ZIP_FILENAME="comprehensive_mime_test_folder.zip" # Changed filename slightly | |
| TEMP_DIR_NAME="mime_test_files_temp" | |
| INTERNAL_FOLDER_NAME="all_test_files" # The folder name inside the zip | |
| # (Extension lists remain the same as before) | |
| EXTENSIONS_TEXT=( | |
| txt log md json xml csv yml yaml ini cfg | |
| html htm css js ts jsx tsx php rb py sh | |
| java c cpp h hpp cs swift kt go rs | |
| sql graphql | |
| ) | |
| EXTENSIONS_IMAGE=( | |
| png jpg jpeg gif webp svg bmp ico | |
| tif tiff heic heif avif | |
| ) | |
| EXTENSIONS_DOCS=( | |
| pdf doc docx xls xlsx ppt pptx odt ods odp rtf | |
| ) | |
| EXTENSIONS_AUDIO=( | |
| mp3 wav ogg aac flac m4a wma | |
| ) | |
| EXTENSIONS_VIDEO=( | |
| mp4 webm mkv flv avi mov wmv | |
| ) | |
| EXTENSIONS_ARCHIVES=( | |
| zip tar gz bz2 xz 7z rar | |
| ) | |
| EXTENSIONS_FONTS=( | |
| ttf otf woff woff2 eot | |
| ) | |
| EXTENSIONS_OTHER=( | |
| bin dat exe dll so appimage dmg pkg | |
| iso vhd vmdk | |
| "NO_EXTENSION_FILE" | |
| "File With Spaces" | |
| ".dotfile_example" | |
| ) | |
| ALL_EXTENSIONS=( | |
| "${EXTENSIONS_TEXT[@]}" | |
| "${EXTENSIONS_IMAGE[@]}" | |
| "${EXTENSIONS_DOCS[@]}" | |
| "${EXTENSIONS_AUDIO[@]}" | |
| "${EXTENSIONS_VIDEO[@]}" | |
| "${EXTENSIONS_ARCHIVES[@]}" | |
| "${EXTENSIONS_FONTS[@]}" | |
| "${EXTENSIONS_OTHER[@]}" | |
| ) | |
| # --- Script Logic --- | |
| # 1. Create a temporary directory | |
| echo "Creating temporary directory: $TEMP_DIR_NAME" | |
| mkdir -p "$TEMP_DIR_NAME/$INTERNAL_FOLDER_NAME" # Create the internal folder as well | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Could not create temporary directory structure '$TEMP_DIR_NAME/$INTERNAL_FOLDER_NAME'." >&2 | |
| exit 1 | |
| fi | |
| # 2. Create 0-byte files *inside the internal folder* | |
| echo "Creating 0-byte test files inside '$INTERNAL_FOLDER_NAME'..." | |
| file_count=0 | |
| pushd "$TEMP_DIR_NAME/$INTERNAL_FOLDER_NAME" > /dev/null # Enter the internal folder | |
| for ext_or_name in "${ALL_EXTENSIONS[@]}"; do | |
| if [[ "$ext_or_name" == *"."* ]] || [[ "$ext_or_name" == "NO_EXTENSION_FILE" ]] || [[ "$ext_or_name" == "File With Spaces" ]] || [[ "$ext_or_name" == ".dotfile_example" ]]; then | |
| filename_to_create="$ext_or_name" | |
| else | |
| filename_to_create="test_file.$ext_or_name" | |
| fi | |
| touch "$filename_to_create" | |
| if [ $? -eq 0 ]; then | |
| file_count=$((file_count + 1)) | |
| else | |
| echo " Warning: Could not create '$filename_to_create'" >&2 | |
| fi | |
| done | |
| echo "Created $file_count test files." | |
| popd > /dev/null # Return to $TEMP_DIR_NAME | |
| # 3. Zip up the *internal folder* (from within $TEMP_DIR_NAME) | |
| echo "Creating zip file: ../$ZIP_FILENAME containing folder '$INTERNAL_FOLDER_NAME'" | |
| pushd "$TEMP_DIR_NAME" > /dev/null # Enter the parent of the internal folder | |
| zip -q -r "../$ZIP_FILENAME" "$INTERNAL_FOLDER_NAME" # Zip the INTERNAL_FOLDER_NAME recursively and quietly | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Could not create zip file." >&2 | |
| popd > /dev/null | |
| cd .. | |
| rm -rf "$TEMP_DIR_NAME" | |
| exit 1 | |
| fi | |
| popd > /dev/null # Return to original directory | |
| # 4. Clean up | |
| echo "Cleaning up temporary directory..." | |
| rm -rf "$TEMP_DIR_NAME" | |
| if [ $? -ne 0 ]; then | |
| echo "Warning: Could not remove temporary directory '$TEMP_DIR_NAME'." >&2 | |
| fi | |
| echo "--------------------------------------" | |
| echo "Test zip file created: $ZIP_FILENAME" | |
| echo "It contains the folder '$INTERNAL_FOLDER_NAME' with $file_count files." | |
| echo "Upload this to your Zip File Explorer tool." | |
| echo "--------------------------------------" | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment