0

I basically have a setup like this:

C:\Upload\A
C:\Upload\B
C:\Upload\C
C:\Upload\D
C:\Upload\E

Where A, B, C, D, E are always different (product IDs) and will always be a different amount (it won't always be 5 sub-directories). Each of these sub-directories contains 24 images numbered numerically 01-24.

I need to create a batch file that looks at the Upload directory, gets the name of each sub-directory and appends that name to beginning of each image file contained within that sub-directory.

So, C:\Upload\A\01.jpg would become C:\Upload\A\A-O1.jpg as well as the other 23 images in each sub-directory.

The batch file needs to do the same for every sub-directory within the Upload directory.

This sounds extremely complicated to me and where I have started to try and write this, I don't yet have anything worth sharing in this post.

Any help will be appreciated.

4

1 に答える 1

5

これにより、「C:\Upload」のサブディレクトリ内のファイルの名前が変更されます

@echo off
for /d %%D in (C:\Upload\*) do (
  for /f "eol=: delims=" %%F in ('dir /b /a-d "%%D" ^| findstr /vbic:"%%~nD-"') do (
    ren "%%D\%%F" "%%~nD-%%F"
  )
)

同じファイルの名前を2回変更しないように、余分なコードを追加しました。スクリプトを複数回安全に実行できるはずです。

各サブディレクトリツリーのファイルの名前を繰り返し変更する場合は、コードを少し変更する必要があります。

@echo off
for /d /r "C:\Utils" %%D in (*) do (
  for /f "eol=: delims=" %%F in ('dir /b /a-d "%%D" ^| findstr /vbic:"%%~nD-"') do (
    ren "%%D\%%F" "%%~nD-%%F"
  )
)
于 2012-07-10T16:45:12.907 に答える