批处理:删除文件扩展名 [英] Batch: Remove file extension

查看:43
本文介绍了批处理:删除文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下来自维基百科的批处理脚本:

@echo offfor/R "C:UsersAdminOrdner" %%f in (*.flv) do (回声%%f)暂停

在 for 循环中,所有扩展名为 flv 的文件都得到回显,但我希望对文件进行一些操作我需要一次不带扩展名的文件和一次带扩展名的文件.我怎么能得到这两个?

我搜索了解决方案,但没有找到.我是一个真正的批处理新手...

解决方案

您可以使用 %%~nf 来获取文件名,只能按照 for:

@echo offfor/R "C:UsersAdminOrdner" %%f in (*.flv) do (回声%%~nf)暂停

以下选项可用:

<前>带修饰符的变量 描述%~I 扩展 %I 删除任何周围引号 ("").%~fI 将 %I 扩展为完全限定的路径名​​.%~dI 仅将 %I 扩展为一个驱动器号.%~pI 仅将 %I 扩展为路径.%~nI 仅将 %I 扩展为文件名.%~xI 仅将 %I 扩展为文件扩展名.%~sI 扩展路径以仅包含短名称.%~aI 将 %I 扩展为文件的文件属性.%~tI 将 %I 扩展到文件的日期和时间.%~zI 将 %I 扩展到文件大小.%~$PATH:I 搜索 PATH 环境中列出的目录变量并将 %I 扩展为的完全限定名称第一个找到了.如果环境变量名称是未定义或搜索未找到该文件,此修饰符扩展为空字符串.

I have the following batch script from Wikipedia:

@echo off
    for /R "C:UsersAdminOrdner" %%f in (*.flv) do (
    echo %%f
)
pause

In the for-loop all files with the extension flv get echoed, but I want the make some actions with the file(s) where I need one time the file without the extension and one time with the extension. How could I get these two?

I searched for solutions but I don't find one. I'm a real newbie in batch...

解决方案

You can use %%~nf to get the filename only as described in the reference for for:

@echo off
    for /R "C:UsersAdminOrdner" %%f in (*.flv) do (
    echo %%~nf
)
pause

The following options are available:

Variable with modifier  Description

%~I                     Expands %I which removes any surrounding 
                        quotation marks ("").
%~fI                    Expands %I to a fully qualified path name.
%~dI                    Expands %I to a drive letter only.
%~pI                    Expands %I to a path only.
%~nI                    Expands %I to a file name only.
%~xI                    Expands %I to a file extension only.
%~sI                    Expands path to contain short names only.
%~aI                    Expands %I to the file attributes of file.
%~tI                    Expands %I to the date and time of file.
%~zI                    Expands %I to the size of file.
%~$PATH:I               Searches the directories listed in the PATH environment 
                        variable and expands %I to the fully qualified name of 
                        the first one found. If the environment variable name is 
                        not defined or the file is not found by the search,
                        this modifier expands to the empty string.    

这篇关于批处理:删除文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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