Re: Extract filename from path



Jeroen Gouma wrote:
> 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

fname=FILENAME; sub(/.*\\/, "",fname)

.



Relevant Pages

  • Re: Extracting filename from path
    ... Sydney, Australia ... > extract the filename part? ... Prev by Date: ...
    (microsoft.public.access.formscoding)
  • Re: Extract filename from path
    ... Jeroen Gouma wrote: ... How can I extract only the filename from the FILENAME variable, ... I often use variants of this, when I look for a character followed by ...
    (comp.lang.awk)
  • Extracting filename from path
    ... Given a directory path string, such as "D:\documents\file1.txt", how do I ... extract the filename part? ... Prev by Date: ...
    (microsoft.public.access.formscoding)
  • Re: Extract filename from path
    ... Jeroen Gouma wrote: ... How can I extract only the filename from the FILENAME variable, ... But how to find the last \ if the lenght of the ...
    (comp.lang.awk)
  • Re: Extract filename from path
    ... pop is Mark ... > How can I extract only the filename from the FILENAME variable, ... Prev by Date: ...
    (comp.lang.awk)