问题描述
我试图调整提供给类似问题的许多代码,但是我不认为解决方案已经发布.我的问题是,我要从中删除其余部分的部分在上一个部分之前存在2次!
I've tried to tweak a lot of the code provided to similar questions, but I don't think the solution is posted. My problem is that the part from where I want to remove the rest exists 2 times before the last!
我拥有的是一个文件夹:
What I have is a folder with:
number1-number2-number3 - some random text about the file.filetype
number1 的范围是01到99
number2 的范围为1-99999
number3 的范围为1-999,可能有2个小数,由整数与整数分隔.
number1 will range from 01 to 99
number2 will range from 1-99999
number3 will range from 1-999 with the possibility of 2 decimals, separated from whole number by .
示例文件夹c:\temp\
:
15-1592-1 - file 1.doc
15-1592-2 - this is file2.pdf
15-1592-3 - this cointains subfiles.html
15-1592-3.1 - sub1.jpg
15-1592-3.2 - sub2.pdf
我需要一个文件夹,其中 number3 之后的所有内容都将从文件名中删除,而且文件类型也保持不变.
What I need is a folder where everything after the end of number3 is removed from the filename, but also the file type unaltered.
示例:
15-1592-1.doc
15-1592-2.pdf
15-1592-3.html
15-1592-3.1.jpg
我了解通过阅读所有答案,这是安静的.
I understand this is quiet possible from reading all the answers combined.
我所缺少的是编译所有知识!
What I lack is the knowledge to compile it all!
推荐答案
您要删除第一个空格之后的所有内容(不带扩展名)
如果使用修饰符(请参见for /?
),这很容易:
You want to delete everything after the first space (without the extension)
This is quite easy, if you use modifiers (see for /?
):
@echo off
setlocal enabledelayedexpansion
for %%a in (??-*-*) do (
for /f "tokens=1 delims= " %%b in ("%%~na") do (
ECHO ren "%%a" "%%b%%~xa"
)
)
这篇关于批量删除部分文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!