使用同一文件夹中的另一个文件名重命名文件名 [英] Rename filename using another files name from the same folder

查看:128
本文介绍了使用同一文件夹中的另一个文件名重命名文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个Windows文件夹,其中只有两个文件: Vacation.jpg 和 summer.avi

I currently have a windows folder with only two files in it: vacation.jpg and summer.avi

我要使用的是.jpg扩展名之前的文本,将Vacation.avi中的summer.avi重命名.

What I want to to is rename summer.avi in vacation.avi by using the text that is before the .jpg extension.

因此,例如,如果我有另一个包含christmas.jpg和summer.avi的文件夹,则.avi文件将重命名为christmas.avi.

So for example if I have another folder with christmas.jpg and summer.avi the .avi file would be renamed into christmas.avi.

任何帮助将不胜感激!

推荐答案

您可以使用~n参数扩展名来仅获取不带扩展名的文件名.该脚本必须与jpg和avi位于同一目录中,但是如果要在多个目录中运行该脚本,则可以将整个内容包装在第二个for循环中.

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
)

这篇关于使用同一文件夹中的另一个文件名重命名文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆