Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Removing File Extensions

by cybermack72 (Novice)
on Feb 27, 2002 at 22:36 UTC ( [id://148065]=perlquestion: print w/replies, xml ) Need Help??

cybermack72 has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to find a way to remove a file extension from a file in Win32. I'm reading in a directory's listing and want to remove the .asc extension from each asci file and verify there is a corresponding .log file (named exactly the same except the extension)

Replies are listed 'Best First'.
Re: Removing File Extensions
by rjray (Chaplain) on Feb 27, 2002 at 22:50 UTC

    Look at File::Basename. This is a part of the Perl core.

    --rjray

Re: Removing File Extensions
by vek (Prior) on Feb 28, 2002 at 00:01 UTC
    For example:
    use File::Basename; # your code here my ($name, $dir, $extension) = fileparse ($theActualFile, '\..*');
    HTH
      Than use move to move em. Bada Bing Bada Bang!
      If you need to do any manipulation involving the path, check out File::Spec. I have found the catfile and splitpath functions to be particularly useful.

      -- grummerX

Re: Removing File Extensions
by YuckFoo (Abbot) on Feb 28, 2002 at 18:07 UTC
    You can also use substitution to build the log filename.

    $logfile = $file; $logfile =~ s/\.asc$/.log/;
    Or maybe you already have a regex to determine if you have a valid ascii filename:
    if ($file =~ m{(.*)\.asc}) { $logfile = "$1.log"; }

    YuckFoo

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://148065]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-26 07:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found