I have two directories with sequential content (i.e., the contents' filenames are 001.jpg, 002.jpg, 003.jpg, and so on up to a maximum of 1000 files). I want to merge them into a new directory in alternating order like so:
Dir1
├── 001.jpg
├── 002.jpg
├── 003.jpg
└── 004.jpg
Dir2
├── 002.jpg
├── 003.jpg
├── 004.jpg
└── 005.jpg
OutputDir
├── 001.jpg (001.jpg from Dir1)
├── 002.jpg (002.jpg from Dir2)
├── 003.jpg (002.jpg from Dir1)
├── 004.jpg (003.jpg from Dir2)
├── 005.jpg (003.jpg from Dir1)
├── 006.jpg (004.jpg from Dir2)
├── 007.jpg (004.jpg from Dir1)
└── 008.jpg (005.jpg from Dir2)
This is what I have but it relies on both dirs having the same names:
cp Dir1/* OutputDir/
cp --backup=existing --suffix=.2 Dir2/* OutputDir/
cd OutputDir
# next line from here: https://stackoverflow.com/questions/3211595/renaming-files-in-a-folder-to-sequential-numbers
ls | cat -n | while read n f; do mv "$f" "$n.jpg"; done
I'm hoping for a solution that doesn't rely on the file names of both directories to be the same.