Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Get file extention from path

Reply
Thread Tools

Get file extention from path

 
 
Ron
Guest
Posts: n/a
 
      07-21-2003
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


 
Reply With Quote
 
 
 
 
Ron
Guest
Posts: n/a
 
      07-21-2003
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$...
> 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 -



 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      07-22-2003
"Ron" <> wrote in news:kE_Sa.93625$hV.6718211
@twister.austin.rr.com:

> "Tina Mueller" <> wrote in message
> news:bfhqic$etufn$...
>> 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: private.php?do=newpm&u=
 
Reply With Quote
 
Ron
Guest
Posts: n/a
 
      07-22-2003
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$...
> >> 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: private.php?do=newpm&u=



 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      07-22-2003
"Ron" <> wrote in
newsc0Ta.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?sourcei...nt&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: private.php?do=newpm&u=
 
Reply With Quote
 
Ron
Guest
Posts: n/a
 
      07-22-2003
"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




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shelve file name extention Monu Python 4 09-11-2008 06:31 PM
change file extention Howard ASP .Net 2 01-05-2006 01:54 PM
How to get file extention from Content-type. shilpa Java 3 06-30-2005 11:05 AM
Strange file extention help Joni Computer Support 4 03-22-2005 06:27 PM
G/H/Y mail Notifier Extention Cron Firefox 4 01-26-2005 03:42 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57