How do I extract just the filename given a fully qualified name (path&name&ext)?

M

Michael Moser

My script gets passed the fully qualified (path & filename & extension)
of some file. How do I extract just the filename?

I found that variables in for-statements allow misc. extraction options,
e.g.:
for %%I in (%parameter%) do echo %~nI

echos just the filename (i.e. without extension) but the result still
contains the path, i.e. the echoed strings reads e.g.
"C:\foo\bar\filename" instead of just "filename".

How can I extract just the local filename of a file in a script?

Michael
 
A

Ayush

Michael Moser wrote ::
My script gets passed the fully qualified (path & filename & extension)
of some file. How do I extract just the filename?

I found that variables in for-statements allow misc. extraction options,
e.g.:
for %%I in (%parameter%) do echo %~nI

echos just the filename (i.e. without extension) but the result still
contains the path, i.e. the echoed strings reads e.g.
"C:\foo\bar\filename" instead of just "filename".

How can I extract just the local filename of a file in a script?

This should work.
In Batch file:
for %%x in (C:\Windows\Regedit.exe) Do @Echo %%~nx

At Command Prompt :
for %x in (C:\Windows\Regedit.exe) Do @Echo %~nx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top