【问题标题】:How to Extract the file name from a full path in bat?如何从bat中的完整路径中提取文件名?
【发布时间】:2014-01-21 11:55:07
【问题描述】:

变量 %result% 包含路径 "D:\My Folder1\My Folder 2\My Folder 3\The Important File.txt" 。我想将The Important File 存储在另一个变量中。即我想从完整路径中提取文件名(无扩展名)。

【问题讨论】:

    标签: batch-file command-line command-prompt


    【解决方案1】:

    这应该可以满足您的需求。

    @echo off
    for %%a in ("%result%") do set "newvariable=%%~na"
    

    【讨论】:

      【解决方案2】:

      【讨论】:

      • 这将包括文件的扩展名。
      • 删除%~x 以截断扩展名。
      • 谢谢两位。下次我会尝试改进我的搜索关键字。
      猜你喜欢
      • 1970-01-01
      • 2015-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-21
      • 1970-01-01
      • 2012-01-11
      相关资源
      最近更新 更多