Solved Batch to move images to folder of same name

Sony / Vgn-nw130d
December 22, 2012 at 15:54:56
Specs: Microsoft Windows 7 Home Premium, 2.1 GHz / 4063 MB
Hey all, it been a while since I've written a script like this. Hopefully you guys can point me in the right direction.

What I'm trying to accomplish is moving images, in this case images of CD covers that will be in the parent folder, into the lowest level subdirectory with the same name.

That's where my confusion comes in. I'm not sure how to go about ensuring it's in the lowest level folder. Some folders will have a folder within it of the same name, for example:

Within the parent directory of all my music, there's a band called Periphery, who has a self-titled album called Periphery as well. I would like to have the album art for this album moved into the album folder, and not the band folder.

I think if I can figure this out I will be able to write the rest of the script myself.

Any ideas anyone?

Thanks, Matt.

Can I put a question here?

See More: Batch to move images to folder of same name

Report •

December 22, 2012 at 18:58:57
I'm confused (as usual). Ok, the base folder has: subfolders of groups, AND the cd covers stored under the album's name. But it seems to me, each album must have some association with a group. I don't see where you are getting that association. F/e, you got cd cover called "abbey road", how do you know it's the beatles?

Report •

December 23, 2012 at 19:52:07
Ah, sorry nbrane! Thank you for taking the time to look at this!

I have a folder called "Music". In this folder, I have saved the album art for the majority of the albums I have stored on my computer. Also in this folder I have folders with the artist names, and within those I have folders for each album. The images are saved with the name of the album.

So, I would like to move, for example, "Music\The Here and Now.jpg" to "Music\Architects\The Here and Now\The Here and Now.jpg"

Where Architects is the name of the band, and The Here and Now is the name of the album.

However, there is the case of self-titled albums, where for example "Music\Periphery.jpg" needs to go into the bottom level folder of the same name. In this case "Music\Periphery\Periphery\Periphery.jpg"

Where Periphery is both the name of the band and the name of the album.

Hopefully all of that made sense?

Thank you for your help!


EDIT: Hmm, I can't say I'm very fond of this new Yahoo! Answers type layout. I can see it being useful for those looking through old posts though.

Can I put a question here?

Report •

December 23, 2012 at 20:48:14
✔ Best Answer
Oh, ok. (! LIGHTBULB !). I think i see (the light). Maybe this:
::====== begin batch
set xx=
@echo off & setlocal enabledelayedexpansion
set xx=
for %%a in (*.jpg) do (
for /f "tokens=*" %%b in ('dir /b /s /ad "%%~na"') do set xx=%%b
echo copy "%%a" "!xx!"
::==== end batch
safety is ON (echo...).

Report •

Related Solutions

December 23, 2012 at 21:35:38
Thank you for your help!

What's happening is the images are being copied into the same folder they are currently in, with a filename of '1' and no file type.

I have no clue as to why this is happening though.

Any ideas?

Thank you again!


Can I put a question here?

Report •

December 23, 2012 at 22:21:20
maybe a "tokens" issue. No clue where the "1" is coming from unless it's part of the filenames of the .jpgs. Also the f_ing spaces i always forget. Might try this:

for /f "tokens=*" %%b in ('dir /b /s /ad "%%~na"') do set xx="%%b"
echo copy "%%a" "!xx!"
(see edited post)
don't know if that will help. give it a try and keep'em crossed. If i could read the "1", I could shed more light, but alas...
thanks, glad things worked. :-)

Report •

December 23, 2012 at 22:33:12
Yes! Thank you! Works great.

Only issue was that if the file didn't have a matching folder it copied it into the folder from the previous copy. However I think I can fix that myself before I actually run it outside of my test folder.

I believe the '1' contained the image data, similar to if you right clicked an image > open in notepad kind of thing. Not sure where it was getting the name from though.

Thanks for all your help nbrane!


EDIT: If you still want to see the file, I've uploaded it here. I now realize the reason for the name being 1 is because I had a test folder named "1 2 3", and stemmed from the token issue. ie,

copy file.jpg 1
which didn't exist.

Thanks again for your help!

Can I put a question here?

Report •

Ask Question