Created
December 7, 2023 18:34
-
-
Save nitatemic/d1912c205a14e8cf33d8a834fc6fe4b4 to your computer and use it in GitHub Desktop.
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 | |
# Check if the argument is provided | |
if [ $# -ne 1 ]; then | |
echo "Usage: $0 <folder_path>" | |
exit 1 | |
fi | |
# Store the folder path provided as an argument | |
folder_path=$1 | |
# Check if the folder exists | |
if [ ! -d "$folder_path" ]; then | |
echo "Folder not found: $folder_path" | |
exit 1 | |
fi | |
# Move files from subfolders to the topmost folder | |
find "$folder_path" -mindepth 2 -type f -exec bash -c 'mv "$1" "${1%/*}/../.." ' _ {} \; | |
# Remove empty directories | |
find "$folder_path" -type d -empty -delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment