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

I have an HTML file (*.htm) on an NT server which I want to move to a different location on that server.

The move should take place from a Perl Script that is updating a database (the database and script are on a different Win2K server). I'd like the script to move the file on the NT server once the database update is done.

Is it possible to do this or not? (I can't use any special Perl modules BTW - I only have a basic Perl installation :-(

Many thanks

  • Comment on Can I use Perl to move an entire HTML file on a different server?

Replies are listed 'Best First'.
Re: Can I use Perl to move an entire HTML file on a different server?
by Corion (Patriarch) on Apr 13, 2006 at 09:07 UTC

    See the rename documentation. Renaming a file also works across directories. It does not work across drive letters or volumes. If you need to "move" the file across volumes, you need to use File::Copy to copy the file and then unlink to delete it.

      Thanks, but the problem I have is referencing the file on the server as this is diferent from the server I am running the script on, this is my move statement at the moment:

      use Win32::ODBC; use File::Copy; move ("http://wwwdev/streams/$Config{'Author'}/$Config{'Ref'}", "http +://wwwybs/ybsone/pipeline/master/13Apr/$Config{'Ref'}") or die "move +failed: S!";
      Have I referenced the file names in the right way (i.e. is http://wwwdev/streams' the correct way to refer to the file)?

      This currently fails for reasons that I don't know.

      I'm not on wwwdev when I run the script BTW.

        The HTTP protocol cannot move or write files. Your idea cannot work. You need to have access to the file system of the target machine.

        Maybe you can use UNC names like this:

        my $machine = 'wwwdev'; my $sharename = 'wwwshare'; my $source = "\\\\$machine\\$sharename\\source\\directory\\filename.tx +t"; my $target = "\\\\$machine\\$sharename\\target\\directory\\new_filenam +e.txt"; rename $source, $target or die "Couldn't move '$source' to '$target' : $!";