You are not logged in.
If I assign a file's full path (e.g, "c:\mydir\text01.txt") to _Fullname using the SET command, is there a way to extract from %_Fullname%:
1. The file's bare name: text01 ?
2. The file's extension: txt ?
3. The file's directory path: c:\mydir ?
4. The file's parent directory: mydir ?
I understand that it's possible to do that with a var created from an argument, as indicated on the ss64's CMD page explaining syntax-args.
But I don't think that those rules apply to a var created by the set command.
Am I mistaken?
Any suggestions about how to parse the path into elements (1 through 4, as itemized above) would be much appreciated.
Thanks,
Marc
Offline
Something like this?
@echo off
set "MyPath=c:\mydir\text01.txt"
call :ExtractParts "%MyPath%
pause
:goto :eof
:ExtractParts
rem 1=filespec
echo(FileSpec=%~1
set "FileName=%~n1"
set "Extension=%~x1"
set "Extension=%Extension:.=%" & rem remove .
set "DirPath=%~dp1"
set "DirPath=%DirPath:~0,-1%" & rem remove trailing \
set "ParentDir=%~p1
set "ParentDir=%ParentDir:\=%" & rem remove leading and trailing \
echo(FileName=%FileName%
echo(Extension=%Extension%
echo(DirPath=%DirPath%
echo(ParentDir=%ParentDir%
goto :eof
:: end of :ExtractParts
Windows Shell Scripting and InstallShield
Offline