我有一个文件destination.txt,其中包含有关我的CD的路径信息:
C:\Users\NekhayenkoO\Desktop\LOG Dateien CD Imaging\SME99.ISO
C:\Users\NekhayenkoO\Desktop\LOG Dateien CD Imaging\Biomasse.iso
C:\Users\NekhayenkoO\Desktop\LOG Dateien CD Imaging\SAMPE36.ISO
现在我必须一个接一个地用PPN.txt文件中的数字重命名ISO:
470692405
394006801
348117876
所以它应该是
SME99.ISO -> 470692405.ISO
Biomasse.iso -> 394006801.ISO
Sampe36.ISO -> 348117876.ISO
我有以下代码:
< "PPN.txt" (for /F "usebackq delims=" %%a in ("destination.txt") do (
set/P out="" & rename "%%a" "!out!%%~xa"
我想修改代码,使其适用于文件destination.txt:
Success on: "C:\Users\NekhayenkoO\Desktop\LOG Dateien CD Imaging\SME99.ISO"
Error on: "C:\Users\NekhayenkoO\Desktop\LOG Dateien CD Imaging\Biomasse.iso"
Success on: "C:\Users\NekhayenkoO\Desktop\LOG Dateien CD Imaging\SAMPE36.ISO"
如果“Success on”保留在destination.txt中的路径之前,则应始终仅使用PPN.txt中的数字重命名该图像。 但是如果“Error on”停留在destination.txt中的路径之前,则应该将此图像重命名为PPN.txt%中的此e_%编号。所以它应该是额外的前缀e_ there
答案 0 :(得分:5)
修改批量现在考虑了前缀,将结肠处的destination.txt
分隔为%%A
和%%B
@Echo off&SetLocal EnableExtensions EnableDelayedExpansion
< "PPN.txt" (
for /F "usebackq tokens=1,* delims=:" %%A in ("destination.txt") do (
Set "out="
Set /P "out="
Set "out=!out: =!"
If /i "%%A" equ "Success on" (
ren %%B "!out!.ISO" && echo Renamed %%B to "!out!.ISO"
) Else If /i "%%A" equ "Error on" (
ren %%B "e_!out!.ISO" && echo Renamed %%B to "e_!out!.ISO"
) Else (Echo unknown prefix "%%~A")
)
)
模拟ISO文件返回此输出:
Renamed "C:\Users\NekhayenkoO\Desktop\LOG Dateien CD Imaging\SME99.ISO" to "470692405.ISO"
Renamed "C:\Users\NekhayenkoO\Desktop\LOG Dateien CD Imaging\Biomasse.iso" to "e_394006801.ISO"
Renamed "C:\Users\NekhayenkoO\Desktop\LOG Dateien CD Imaging\SAMPE36.ISO" to "348117876.ISO"
答案 1 :(得分:2)
尝试:
< PPN.txt (
for /F "delims=" %%a in (destination.txt) do (
set/P out="" & rename "%%a" "!out!%%~xa"&&echo Success on: "%%a"||(
echo Error on: "%%a" & rename "%%a" "e_!out!%%~xa"
)
)
)
&&
将处理先前操作的成功(errorlevel
0),||
将处理失败。