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.
Asked
Active
Viewed 2,214 times
2

Deb
- 5,163
- 7
- 30
- 45
2 Answers
3
This should give you what you need.
@echo off
for %%a in ("%result%") do set "newvariable=%%~na"

foxidrive
- 40,353
- 10
- 53
- 68
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.

Community
- 1
- 1

Ben Crowhurst
- 8,204
- 6
- 48
- 78
-
This will include the extension of the file. – Deb Jan 21 '14 at 12:00
-
1remove the `%~x` to truncate the extension. – npocmaka Jan 21 '14 at 12:09
-
Thank you both. Next time I will try to improve my search keywords. – Deb Jan 21 '14 at 18:29