Get file extention from path

Discussion in 'Perl Misc' started by Ron, Jul 21, 2003.

  1. Ron

    Ron Guest

    I need to get the file extension from a path(file location+file
    name+extension)

    This code get's me to the file name + extension.

    My beginner question is. How do I get just the extension?

    my $filename1 = $FILE1;
    $filename1 =~ s/^.*(\\|\/)//;
    $filename1 =~ s/ +/\_/g;

    Thanks,
    Ron
     
    Ron, Jul 21, 2003
    #1
    1. Advertising

  2. Ron

    Ron Guest

    Thanks Tina although I am not sure who to put that into code I tried

    my $ext1 = $FILE1(function fileparse());

    How do I use it?

    Thanks,
    Ron

    "Tina Mueller" <> wrote in message
    news:bfhqic$etufn$-berlin.de...
    > Ron wrote:
    > > I need to get the file extension from a path(file location+file
    > > name+extension)

    >
    > perldoc File::Basename
    > (function fileparse())
    >
    > hth, tina
    > --
    > http://www.tinita.de/ \ enter__| |__the___ _ _ ___
    > http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
    > http://www.perlquotes.de/ \ \ _,_\ __/\ __/_| /__/ perception
    > - my mail address expires end of august 2003 -
     
    Ron, Jul 22, 2003
    #2
    1. Advertising

  3. "Ron" <> wrote in news:kE_Sa.93625$hV.6718211
    @twister.austin.rr.com:

    > "Tina Mueller" <> wrote in message
    > news:bfhqic$etufn$-berlin.de...
    >> Ron wrote:
    >> > I need to get the file extension from a path(file location+file
    >> > name+extension)

    >>
    >> perldoc File::Basename
    >> (function fileparse())
    >>
    >> hth, tina

    > Thanks Tina although I am not sure who to put that into code I tried
    >
    > my $ext1 = $FILE1(function fileparse());
    >
    > How do I use it?


    First, do not top-post.

    Second, do read the posting guidelines for this group. They are posted here
    regularly, and available at:

    http://mail.augustmail.com/~tadmc/clpmisc.shtml

    Third, RTFM!

    http://www.perldoc.com/perl5.6/lib/File/Basename.html

    Sinan.

    --
    A. Sinan Unur

    Remove dashes for address
    Spam bait: mailto:
     
    A. Sinan Unur, Jul 22, 2003
    #3
  4. Ron

    Ron Guest

    Thanks Sinan,

    I am so new I did not even know about TFM.

    I did take the time to read the posting guide lines & thought of you when I
    read the first paragrah.

    " A note to newsgroup ``regulars'':
    Do not use these guidelines as a "license to flame" or other
    meanness. It is possible that a poster is unaware of things
    discussed here. Give them the benefit of the doubt, and just
    help them learn how to post, rather than assume"

    "A. Sinan Unur" <> wrote in message
    news:Xns93BFD05838C85asu1cornelledu@132.236.56.8...
    > "Ron" <> wrote in news:kE_Sa.93625$hV.6718211
    > @twister.austin.rr.com:
    >
    > > "Tina Mueller" <> wrote in message
    > > news:bfhqic$etufn$-berlin.de...
    > >> Ron wrote:
    > >> > I need to get the file extension from a path(file location+file
    > >> > name+extension)
    > >>
    > >> perldoc File::Basename
    > >> (function fileparse())
    > >>
    > >> hth, tina

    > > Thanks Tina although I am not sure who to put that into code I tried
    > >
    > > my $ext1 = $FILE1(function fileparse());
    > >
    > > How do I use it?

    >
    > First, do not top-post.
    >
    > Second, do read the posting guidelines for this group. They are posted

    here
    > regularly, and available at:
    >
    > http://mail.augustmail.com/~tadmc/clpmisc.shtml
    >
    > Third, RTFM!
    >
    > http://www.perldoc.com/perl5.6/lib/File/Basename.html
    >
    > Sinan.
    >
    > --
    > A. Sinan Unur
    >
    > Remove dashes for address
    > Spam bait: mailto:
     
    Ron, Jul 22, 2003
    #4
  5. "Ron" <> wrote in
    news:eek:c0Ta.93830$:

    > Thanks Sinan,
    >
    > I am so new I did not even know about TFM.
    >
    > I did take the time to read the posting guide lines & thought of you
    > when I read the first paragrah.
    >
    > " A note to newsgroup ``regulars'':
    > Do not use these guidelines as a "license to flame" or other
    > meanness. It is possible that a poster is unaware of things
    > discussed here. Give them the benefit of the doubt, and just
    > help them learn how to post, rather than assume"


    Hmmmm ... my post was no flame.

    And please stop top-posting.

    BTW,

    > my $ext1 = $FILE1(function fileparse());


    is profoundly weird, and indicated to me that you spent no effort. A simple
    Google search for fileparse returns the link I gave you as the first match:

    http://www.google.com/search?sourceid=navclient&q=fileparse

    so you did not even have to know where the docs are located on your
    computer.

    Sinan.
    --
    A. Sinan Unur

    Remove dashes for address
    Spam bait: mailto:
     
    A. Sinan Unur, Jul 22, 2003
    #5
  6. Ron

    Ron Guest

    "Shawn Corey" <> wrote in message
    news:...
    > Hi,
    >
    > perldoc File::Basename
    >
    > Read about fileparse.
    >
    > Ron wrote:
    >
    > > I need to get the file extension from a path(file location+file
    > > name+extension)
    > >
    > > This code get's me to the file name + extension.
    > >
    > > My beginner question is. How do I get just the extension?
    > >
    > > my $filename1 = $FILE1;
    > > $filename1 =~ s/^.*(\\|\/)//;
    > > $filename1 =~ s/ +/\_/g;
    > >
    > > Thanks,
    > > Ron
    > >


    Thanks I read the doc. I hate to ask for more help but here goes.
    From the doc I got;
    Similarly, using VMS syntax:

    ($name,$dir,$type) = fileparse('Doc_Root:[Help]Rhetoric.Rnh',
    '\..*');





    When I run this code I get a server error?
    I am trying to get the file extention from $FILE1.


    fileparse($FILE1 ,'\..*');
    My $MyExt1 eq $type

    Any Suggestions or code I might use?

    Thanks,
    Ron
     
    Ron, Jul 22, 2003
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Carl Ogawa

    How do I make .cgi extention work?

    Carl Ogawa, Dec 27, 2003, in forum: Perl
    Replies:
    1
    Views:
    1,011
  2. Howard

    change file extention

    Howard, Jan 5, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    2,040
    Teemu Keiski
    Jan 5, 2006
  3. shilpa
    Replies:
    3
    Views:
    8,858
    shilpa
    Jun 30, 2005
  4. Jesper Olsen

    C++ extention

    Jesper Olsen, Nov 18, 2003, in forum: Python
    Replies:
    2
    Views:
    458
    Jesper Olsen
    Nov 18, 2003
  5. Monu

    shelve file name extention

    Monu, Sep 8, 2008, in forum: Python
    Replies:
    4
    Views:
    400
    Fredrik Lundh
    Sep 11, 2008
Loading...

Share This Page