小编典典

批处理:删除文件扩展名

all

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

@echo off
    for /R "C:\Users\Admin\Ordner" %%f in (*.flv) do (
    echo %%f
)
pause

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

我搜索了解决方案,但没有找到。我是批次的真正新手…


阅读 84

收藏
2022-08-07

共1个答案

小编典典

%%~nf只能按照以下参考中的描述使用来获取文件名for

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

可以使用以下选项:

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.   
2022-08-07