1

I have a folder called "tokens". In this folder, I have several other folders, called things like "guard", "noble", "assassin", etc. In those folders are image files with varying names and file formats.

I would like to run through the all the folders and files in "tokens", and rename each file to be whatever directory it is in with a number appended to it. So, a file in the "guard" folder would be named "guard0001.jpg", and the next would be "guard0002.png", for instance.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Regniwekim
  • 11
  • 3

1 Answers1

0

There are certainly better/faster approaches but this should do the trick.

find tokens -type f -exec sh -c "path='{}'"'; file="${path##*/}"; dir="${path%/*}"; folder="${dir##*/}"; echo mv "$path $dir/$folder$file"' \;

Remove the echo when you're satisfied with the output it produced.

Darkman
  • 2,941
  • 2
  • 9
  • 14