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?
1 Answer
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.