Substrings with DOS
Posted: 30 Jul 2009 09:38
I've a string containing the full path to a text file and i'd like to extract only the name of the text file.
For example d:\myfolder\myfile.txt
I can get the path of the file using the code below, but i cant get the name of the file
I tried to use a count and then use the substring function but it doesn't work, this is the code i use for the substring
Is there any other command that would let me get the name of a file from a full path, or is there an addition to the code i already have to do it?
Thanks in advance
For example d:\myfolder\myfile.txt
I can get the path of the file using the code below, but i cant get the name of the file
Code: Select all
SET Var=d:\myfolder\myfile.txt
For %%i in (%Var%) Do Set CF=%%i
Set CF=%CF:~0,-1%
:LOOP
If "%CF:~-1,1%"=="\" GoTo :DONE
Set CF=%CF:~0,-1%
GoTo :LOOP
:DONE
Set CF=%CF:~0,-1%
Echo %CF%
I tried to use a count and then use the substring function but it doesn't work, this is the code i use for the substring
Code: Select all
SET VAR=%VAR:~-%COUNT%,%COUNT%%
Is there any other command that would let me get the name of a file from a full path, or is there an addition to the code i already have to do it?
Thanks in advance