问题
I currently have a windows folder with only two files in it: vacation.jpg and summer.avi
What I want to to is rename summer.avi in vacation.avi by using the text that is before the .jpg extension.
So for example if I have another folder with christmas.jpg and summer.avi the .avi file would be renamed into christmas.avi.
Any help would be much appreciated!
回答1:
You can use the ~n
parameter extension to grab just the filename without the extension. The script needs to be in the same directory as the jpg and avi, but if you want to run it on multiple directories, you can wrap the whole thing in a second for
loop.
@echo off
setlocal enabledelayedexpansion
:: This assumes there is only one avi file in the folder
for /F %%A in ('dir /b *.jpg') do (
set basename=%%~nA
ren *.avi !basename!.avi
)
回答2:
This should worlk, though I haven't tested it:
@echo off
for %%i in (*.jpg) do set src=%%i
ren *.avi %src%
来源:https://stackoverflow.com/questions/28943950/rename-filename-using-another-files-name-from-the-same-folder