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

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

问题描述

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

  @echo off 
for / RC: \ers/\\Admin\Ordner%% f in(* .flv)do(
echo %% f

pause
/ pre>

在for循环中,所有具有扩展名flv的文件都被回显,
,但是我想要使用文件$ b进行一些操作$ b其中我需要一次没有扩展名的文件,一次扩展名。
我如何得到这两个?



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

解决方案

您可以使用% %〜nf 只能按照 for

  @echo off 
for / RC:\Users\Admin\Ordner%% f in(* .flv)do(
echo %% 〜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:\Users\Admin\Ordner" %%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:\Users\Admin\Ordner" %%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天全站免登陆