Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Usig file name without backslash escape

by jwkrahn (Abbot)
on Jun 28, 2012 at 01:15 UTC ( [id://978811]=note: print w/replies, xml ) Need Help??


in reply to Usig file name without backslash escape

foreach (@FILES) { my $newFile="$currentDir"."\/".$file; my $curFile="$oldDir"."\/".$file;

That should be:

foreach my $file (@FILES) { my $newFile = $curDir."/".$file; my $curFile = $newDir."/".$file;

Replies are listed 'Best First'.
Re^2: Usig file name without backslash escape
by rkrasowski (Sexton) on Jun 28, 2012 at 03:00 UTC
    Ups, sorry I did not check the code before sending a question. This is corrected code:
    #!/usr/bin/perl use strict; use warnings; my $newDir = "/home/iphone/Maildir/new"; my $curDir = "/home/iphone/MailDir/cur"; my $file; opendir(DIR, "$newDir"); my @FILES= readdir(DIR); closedir DIR; foreach (@FILES) { $file = $_; my $newFile=$newDir."\/".$file; my $curFile=$curDir."\/".$file; print "$newFile\n"; print "$curFile\n"; rename $newFile, $curFile; }
    Response that I am getting is this: /home/iphone/Maildir/new/. /home/iphone/MailDir/cur/. /home/iphone/Maildir/new/1340841279.M908367P21767.krasowski,S=2294,W=2338 /home/iphone/MailDir/cur/1340841279.M908367P21767.krasowski,S=2294,W=2338 /home/iphone/Maildir/new/.. /home/iphone/MailDir/cur/.. /home/iphone/Maildir/new/1340841583.M454288P21927.krasowski,S=2339,W=2384 /home/iphone/MailDir/cur/1340841583.M454288P21927.krasowski,S=2339,W=2384 But no file is moved. Hmm, Any idea what is th problem? Why I can not move these files?? Thanks Robert

      Have you tried asking Perl what the problem is?

      rename $newFile, $curFile or die $!;

      Aaron B.
      Available for small or large Perl jobs; see my home node.

      From rename in perldoc:

      Behavior of this function varies wildly depending on your system implementation. For example, it will usually not work across file system boundaries, even though the system mv command sometimes compensates for this. Other restrictions include whether it works on directories [...]
      For a platform independent move function look at the File::Copy module.

      — which is why you should prefer the solution given by Kenosis, below.

      Athanasius <°(((><contra mundum

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://978811]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-25 18:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found