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


by jrsmith (Pilgrim)
on May 24, 2000 at 20:19 UTC ( #14586=perlquestion: print w/replies, xml ) Need Help??
jrsmith has asked for the wisdom of the Perl Monks concerning the following question:

does the rename function delete the primary file regardless of whether the rename succeeds? i tested this and it seems as if this is true, is there any way to keep it from doing this or am i going to have to come up with some kind of workaround?
thanx for any help..

Replies are listed 'Best First'.
Re: rename
by lhoward (Vicar) on May 24, 2000 at 20:36 UTC
    The safe way to do this is to use the link/unlink commands. (pseudocode below)
    link file to new name/location
    if error
        handle error
        unlink old filename/location
    note that this won't work if you are renaming across partitions on UNIX (but then neither will the rename command).
RE: rename
by mikfire (Deacon) on May 25, 2000 at 06:55 UTC
    For the platofrm generic way, I would direct your attention to the core module File::Copy.

    From the perldoc pages, I quote

      If possible, move() will simply rename the file.
      Otherwise, it copies the file to the new location and
      deletes the original.  If an error occurs during this
      copy-and-delete process, you may be left with a
      (possibly partial) copy of the file under the
      destination name.
    which seems to handle both the platform dependant issues as well as the the question jrsmith asked.

    Mik Firestone ( perlus bigotus maximus )

Re: rename
by jrsmith (Pilgrim) on May 24, 2000 at 21:37 UTC
    just my luck, link is unsupported in win32
      I never use win32, but I imagine something like this would work (pseudo-code below):
      copy file from old name to new name if error handle error else delete old file
      Weird. Unlink() is implemented.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://14586]
Approved by root
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2018-06-24 02:19 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.