Вопрос

Apologies if this has been answered, the search gives something similar but not exactly what I'm after.

I use XBMC and a Western Digital TV Live as media centers. XBMC uses folder.jpg for movie box art. However, the WD uses both folder.jpg and moviename.jpg.

My folder structure is as follows:

Films\movie1\movie1.mkv(or avi etc...)
Films\movie1\folder.jpg
Films\movie2\movie2.mkv (etc...)
Films\movie2\folder.jpg

What I'm after is a .bat file that will scan the entire films directory, copy the folder.jpg and rename the new jpg using the name of the folder that folder.jpg is in. The original folder.jpg should remain.

Essentially from:

Films\movie1\folder.jpg

To:

Films\movie1\folder.jpg

and

Films\movie1\movie1.jpg

This should happen to each folder in Films.

I'm sure this must be possible but to be honest my knowledge of .bat files is very limited.

Это было полезно?

Решение

You can use a FOR /D loop to iterate over subdirectories of Films:

@ECHO OFF
FOR /D %%I IN ("D:\Path\to\Films\*") DO (
  COPY "%%I\folder.jpg" "%%I\%%~nxI.jpg"
)

In the loop, the subdirectory's full path is referenced as %%I and its name alone as %%~nxI (could be just %%~nI if the name never includes a .).

You could run the loop directly from the command prompt, but you'd need to replace the double % characters with single %:

FOR /D %I IN ("D:\Path\to\Films\*") DO COPY "%I\folder.jpg" "%I\%~nxI.jpg"

Please note also that if a moviename.jpg already exists, the COPY command will stop for confirmation of overwriting the file. If you just want to overwrite it anyway without manual confirmation, add the /Y switch:

COPY /Y ...

Другие советы

for /d %%a in (*) do if exist "%%~a\folder.jpg" echo copy /b "%%~a\folder.jpg" "%%~a\%%~na.jpg"

Remove the echo to get it working.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top