PDA

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


Michael Moser
March 2nd 07, 01:10 PM
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

Ayush
March 4th 07, 01:17 AM
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

Google