I currently have a windows folder with only two files in it: vacation.jpg and summer.avi
我目前有一个只包含两个文件的Windows文件夹:vacation.jpg和summer.avi
What I want to to is rename summer.avi in vacation.avi by using the text that is before the .jpg extension.
我想要的是使用.jpg扩展名之前的文本在vacation.avi中重命名summer.avi。
So for example if I have another folder with christmas.jpg and summer.avi the .avi file would be renamed into christmas.avi.
例如,如果我有另一个带有christmas.jpg和summer.avi的文件夹,那么.avi文件将被重命名为christmas.avi。
Any help would be much appreciated!
任何帮助将非常感激!
2 个解决方案
#1
0
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.
你可以使用~n参数扩展来获取没有扩展名的文件名。该脚本需要与jpg和avi位于同一目录中,但是如果要在多个目录上运行它,可以将整个内容包装在第二个for循环中。
@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
-1
This should worlk, though I haven't tested it:
这应该是worlk,虽然我还没有测试过:
@echo off
for %%i in (*.jpg) do set src=%%i
ren *.avi %src%
#1
0
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.
你可以使用~n参数扩展来获取没有扩展名的文件名。该脚本需要与jpg和avi位于同一目录中,但是如果要在多个目录上运行它,可以将整个内容包装在第二个for循环中。
@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
-1
This should worlk, though I haven't tested it:
这应该是worlk,虽然我还没有测试过:
@echo off
for %%i in (*.jpg) do set src=%%i
ren *.avi %src%