How to Extract the file name from a full path in bat?

大城市里の小女人 提交于 2019-12-23 04:06:55

问题


A variable %result% contains the path "D:\My Folder1\My Folder 2\My Folder 3\The Important File.txt" . I want to store The Important File in some another variable. That is, I want to extract the file name (Without extention) from a full path.


回答1:


This should give you what you need.

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



回答2:


You'll find a solution here: Get the file name from a full or relative path knowing that this one is not a parameter of the batch

here: Get filename from string-path?

here: In Batch: Read only the filename from a variable with path and filename

Please search existing questions before creating duplicates.



来源:https://stackoverflow.com/questions/21257407/how-to-extract-the-file-name-from-a-full-path-in-bat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!