Split a filename containing wildcards in path and name without expanding the wildcards
Posted: 01 Dec 2024 21:41
I want to split a filename that contains wildcards in "drive:path" and "name.ext"
For example:
@echo off
echo path=%~dp1
echo name=%~nx1
It works if the filename does not contain wildcards, i.e. with filename=c:\mypath\myname.ext you get
path=c:\mypath\
name=myname.ext
But it does not work if the filename contains wildcards, i.e. filename=c:\mypath\*.c
I would like to obtain:
path=c:\mypath\
name=*.c
But the syntax %~nx1 expands the wildcards. If there is no any file that can be expanded by the wildcards you get the correct result but, if for example a file named c:\mypath\myname.c exists, then you get:
path=c:\mypath\
name=myname.c
How can I split without expanding the wildcards?
Thanks
For example:
@echo off
echo path=%~dp1
echo name=%~nx1
It works if the filename does not contain wildcards, i.e. with filename=c:\mypath\myname.ext you get
path=c:\mypath\
name=myname.ext
But it does not work if the filename contains wildcards, i.e. filename=c:\mypath\*.c
I would like to obtain:
path=c:\mypath\
name=*.c
But the syntax %~nx1 expands the wildcards. If there is no any file that can be expanded by the wildcards you get the correct result but, if for example a file named c:\mypath\myname.c exists, then you get:
path=c:\mypath\
name=myname.c
How can I split without expanding the wildcards?
Thanks