John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

I know about the File::Copy module that copies files and will call platform-specific stuff if applicable, but handles more cases and works on any platform.

What about moving a file? I can call Win32API::File::MoveFile, but that only works on Windows and doesn't do any the neat stuff like File::Copy (works with streams, not just names).

Is there something to use for moving files that's portable and hides platform details?

I suppose the bulk of the benifit from using underlying OS calls comes from the Copy phase (e.g. being able to copy a compressed or encrypted file without "reading" and re-writing it; setting the dates and permissions and *whatever* weird attributes to match the original), and a copy followed by a delete ought to be good enough. But the native move would further optimize the case where the file is on the same file system and only the directory entry actually moves.

Replies are listed 'Best First'.
Re: What's the best way to "move" a file?
by sauoq (Abbot) on Oct 30, 2002 at 21:06 UTC

    File::Copy also provides a move() function. It renames if possible and copies/deletes if not.

    -sauoq
    "My two cents aren't worth a dime.";