File Renaming Problem (Please Help...) 
Author Message
 File Renaming Problem (Please Help...)

Hi I am having trouble renaming a file and I have absolutely no idea
why.

Here is my code:
--- start

    {
      chomp;
      $name = basename($file);
      $destname = "$spooldir/$name";
      $tmpname = $destname;
      $tmpname =~ s/std/incomplete/g; #copy as incomplete before
renaming as std
      if (rename("$file","$tmpname") == 0) { print "ren1 failed: $!\n";

Quote:
}

      if (rename("$tmpname","$destname") == 0) { print "ren2 failed:
$!\n"; }
      print "MOVING COMMAND: mv $file $destname\n";
    }
--- end

I am trying to move a file from one directory to another (with an
intermediate step which is necessary
because the final directory has a daemon which will pick up any files
matching *std*)

Here is the output I get when I run the code
--- start
ren1 failed: No such file or directory
ren2 failed: No such file or directory
MOVING COMMAND: mv
/nt/users/zcrks46c_1/firms/spool/tester/teak_FNR_b11ext_1d10_b11e_cf_failures_apr03_10_31.stdf

 /nt/users/zcrks46c_1/firms/spool/stdf/teak_FNR_b11ext_1d10_b11e_cf_failures_apr03_10_31.stdf

--- end

The problem is if I run the "MOVING COMMAND" manually there is no
problem.
If I rely on the "rename(src,dest) method it returns an error. Why Why
Why???????



Tue, 19 Sep 2000 03:00:00 GMT  
 File Renaming Problem (Please Help...)

Daniel,

    rename() does not work across filesystems, just like "mv". I suspect
your spooldir is on another filesystem. You would then need to copy and
delete twice. Why not just move it straight to the destination directory
with the new name?

hth
Eric

Quote:

>Hi I am having trouble renaming a file and I have absolutely no idea
>why.

>Here is my code:
>--- start

>    {
>      chomp;
>      $name = basename($file);
>      $destname = "$spooldir/$name";
>      $tmpname = $destname;
>      $tmpname =~ s/std/incomplete/g; #copy as incomplete before
>renaming as std
>      if (rename("$file","$tmpname") == 0) { print "ren1 failed: $!\n";
>}
>      if (rename("$tmpname","$destname") == 0) { print "ren2 failed:
>$!\n"; }
>      print "MOVING COMMAND: mv $file $destname\n";
>    }
>--- end

>I am trying to move a file from one directory to another (with an
>intermediate step which is necessary
>because the final directory has a daemon which will pick up any files
>matching *std*)

>Here is the output I get when I run the code
>--- start
>ren1 failed: No such file or directory
>ren2 failed: No such file or directory
>MOVING COMMAND: mv
>/nt/users/zcrks46c_1/firms/spool/tester/teak_FNR_b11ext_1d10_b11e_cf_failur
es_apr03_10_31.stdf

/nt/users/zcrks46c_1/firms/spool/stdf/teak_FNR_b11ext_1d10_b11e_cf_failures_
apr03_10_31.stdf

- Show quoted text -

Quote:

>--- end

>The problem is if I run the "MOVING COMMAND" manually there is no
>problem.
>If I rely on the "rename(src,dest) method it returns an error. Why Why
>Why???????



Fri, 22 Sep 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. File Renaming Problem (Please Help...)

2. Help w Script to Rename Files Please.

3. renaming file problem (rename / mv)

4. "Rename-File-Names" Script Needed, Please

5. "Rename-File-Names" Script Needed, Please

6. "Rename-File-Names" Script Needed, Please

7. CGI.pm file upload problem - Please Help!

8. crypt in required file problem, please help

9. Reading large files problem, please help.

10. CGI.pm file upload problem - Please Help!

11. Newbie has <FILE> Problem - please help

 

 
Powered by phpBB® Forum Software