Moving multiple subfolder files to parent folder on Mojave?
In Terminal run
cd PARENTFOLDER
mkdir -p $TMPDIR/move
mv */* $TMPDIR/move/
rmdir *
mv $TMPDIR/move/* .
rmdir $TMPDIR/move
Please note
- This will lead to data loss if files in different subfolders have the same name.
-
rmdir *
will fail if the subfolders aren't empty after the move (e.g. if they contain files/directories starting with a.
) - It works by first moving the files within the subfolders to a temporary location, then removing the subfolders themselves and then moving the files from them temporary location back to the parent. The moves are fast if they are on the same drive, they are very slow (and may fail due to lack of disk space) if the parent folder is on an external drive
For the extended version you've asked in the comments
Is there an easy way to batch apply this for an entire folder? For example: Year (parent folder) > Month > Day 1, 2, etc. Where I can apply your function to every folder in Year, with the contents of Day 1 & 2 going into Month, but the content of Month don't go into Year?
_tmp=$(mktemp -d)
cd YEAR
for month in *; do
[[ -d "$month" ]] || continue
echo mv -- "$month"/*/* "$_tmp"/
echo rmdir -- "$month"/*
echo mv "$_tmp"/* "$month"/
done
rmdir "$_tmp"
Remove the echo
s if the output of the dry run looks ok.