Moving multiple subfolder files to parent folder on Mojave? I'm trying to move the files of multiple (100+) subfolders to the parent folder, but I don't want to do it manually for each. Is there something I could do to automate that?
I've tried solutions for older OS's and they don't seem to work, and I don't fully understand https://discussions.apple.com/thread/8385501
Thank you!
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) &gt; Month &gt; Day 1, 2, etc. Where I can apply your function to every folder in Year, with the contents of Day 1 &amp; 2 going into Month, but the content of Month don't go into Year?

_tmp=$(mktemp -d)
cd YEAR
for month in *; do
    [[ -d &quot;$month&quot; ]] || continue

    echo mv -- &quot;$month&quot;/*/* &quot;$_tmp&quot;/
    echo rmdir -- &quot;$month&quot;/*
    echo mv &quot;$_tmp&quot;/* &quot;$month&quot;/
done
rmdir &quot;$_tmp&quot;

Remove the echos if the output of the dry run looks ok.