Extract filename from path



Hi,

How can I extract only the filename from the FILENAME variable,
containing the complete path?

i.e.:
FILENAME = c:\test\input\data.txt

I would like to have only data.txt in a variable.

I was thinking on something like find the last \ in FILENAME and take
a substr from there. But how to find the last \ if the lenght of the
path can vary?

Thanks a lot,

Jeroen
.



Relevant Pages

  • Re: Extracting filename from path
    ... Sydney, Australia ... > extract the filename part? ... Prev by Date: ...
    (microsoft.public.access.formscoding)
  • Re: OpenFileDialog and passing a relative directory automaticly to it
    ... i have a circumstance where a user unzips a file, with a certain layer ... in most cases i can be sure the zip fie will extract as shown, ... If you know the actual filename, _and_ you know that filename is unique within the subdirectories that have been extracted, then you could do a search of that subtree of the file system to find the file. ... Just because the files can be extracted anywhere, that doesn't preclude using absolute paths. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How do I extract a filename from a formula linked to another book
    ... You need some VBA code to extract the formula as a text string then you can ... extract the filename from that text string. ... Copy/paste the above code into the window that opens ...
    (microsoft.public.excel.misc)
  • Re: Creating Filename from Form Data
    ... > data from Form fields and create a filename. ... > difficulty modifying it successfully to extract the data from my form ... If there's an error message, ... also tell us where you got the macro example so we can ...
    (microsoft.public.word.docmanagement)
  • Re: How do I extract just the filename given a fully qualified name (path&name&ext)?
    ... How do I extract just the filename? ... extraction options, e.g.: ... for %%I in do echo %~nI ... How can I extract just the local filename of a file in a script? ...
    (microsoft.public.windowsxp.customize)