CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
copy a file

 



fishfork
Novice

Mar 25, 2001, 8:55 AM

Post #1 of 4 (347 views)
copy a file Can't Post

When a record is added to my database a GIF file and a JPEG file provided by the user are placed in a directory which corresponds to the record in the database. If no file is supplied I want to copy a blank file into the directory. How?

Using the ucual file handles the file is copied as text (or something) and it doesn't work. Is there a way to use a simple UNIX mv command?

Thanks



freddo
User

Mar 25, 2001, 9:43 AM

Post #2 of 4 (345 views)
Re: copy a file [In reply to] Can't Post

Hello,

for moving a file, you can use the perl function rename like:

rename "oldfile","newfile";

but i just read there may be compatibility problems for directories depending on the OS. For more informations, try:

perldoc -f rename
perldoc perlport

You can also use File::Copy (for both copy and/or move), this was taken from "perldoc file::copy" ...

use File::Copy;
copy("file1","file2");
move("file1","file2");

i hope this helps
see you



fishfork
Novice

Mar 25, 2001, 3:02 PM

Post #3 of 4 (339 views)
Re: copy a file [In reply to] Can't Post

Tried using File::Copy, but I get the same problem: The resulting file is not a valid JPEG or GIF. (I have checked that the originals are).

??



freddo
User

Mar 26, 2001, 2:29 PM

Post #4 of 4 (326 views)
Re: copy a file [In reply to] Can't Post

Hello,

i just tried this little script:

#/usr/bin/perl
use File::Copy;

mkdir "zzz" or die "keuf! $!";;
copy("noos.gif", "zzz/noos.gif") or die "arrgh! $!";
copy("jacky.jpg", "zzz/jacky.jpg") or die "arrgh! $!";

and it works fine under: linux, win32 activestate perl, and cygnus'perl win32 port... ?

are you sure you're not making something wrong?



 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives