Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Changing filename extensions

by jwkrahn (Abbot)
on Nov 16, 2021 at 03:44 UTC ( [id://11138862]=note: print w/replies, xml ) Need Help??


in reply to filenames

$dir is not the current directory so you are renaming nonexistant files in the current directory.

Either change the current directory to where the files are or include $dir as part of the path when renaming.

Replies are listed 'Best First'.
Re^2: Changing filename extensions
by supernova95 (Initiate) on Nov 16, 2021 at 03:51 UTC

    Forgive me I'm a newbie at Perl, how do I include $dir as part of the path?

      rename("$dir/$name.$old", "$dir/$name.$new");

        Given the OP is a Perl newbie, just a further clarification that when running Perl on Windows, forward slashes are preferred to backslashes. This enhances code portability because they work fine in file paths when using Perl on both Unix and Windows (as described in more detail at Re^4: windows perl and paths) and boosts enjoyment because they are easier to type and read than ugly escaped backslashes. :)

        That did the trick, tysm!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2024-04-19 13:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found