2

I have a folder containing CD covers in .jpg and another folder containing subfolders, each with the corresponding CD. I want to send each CD cover to its corresponding subfolder. They are already alphabetically ordered. How can I do that?

2
  • The CD Covers filenames are the same as the corresponding subfolder with that CD? Feb 26, 2018 at 0:58
  • No, but when put in alphabetical order, the positions are corresponding.
    – Rodrigo
    Feb 26, 2018 at 1:05

1 Answer 1

4

This is the kind of thing that's easy with a Unix shell. You could do this with bash as well but here's how you might do it with the free demo version of my Hamilton C shell. (Yes, I'm the author.)

Assume you're in the directory containing the jpgs and that directory-containing-CDs is the path to the directory with the subdirectories with the CDs:

set CDs = ``ld -1 directory-containing-CDs``  # Get list of CD directories
set covers = *.jpg  # Get the list of jpgs
for i = 0 to $#covers - 1 do
   mv $covers[i] directory-containing-CDs\$CDs[i]  # Move the jpgs one-at-a-time.
end

ld is an alias for running ls, returning only directories. The -1 option means write each directory to a separate line. The double backquotes turn each line into a separate word (if any directory names contain spaces, we don't want to split them into separate words).

If any of this isn't clear, just ask.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .