Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Move using File::Find

by grashoper (Monk)
on Apr 30, 2009 at 20:27 UTC ( #761158=perlquestion: print w/replies, xml ) Need Help??

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

I can't figure out whats wrong with my move file, it seems to want to start in the root of c and I cannot seem to make it not start there. so I was going to try using file:find, I came up with this but of course it doesn't work because perl absolutely hates me and I am still a perltard. this dies with an invalid top directory in line 593. the current directory is not a top level directory though its in c:\inetpub\performancetesting\output\mlx which is where I want the file:find to start recursively moving files from and I want them put into a tree that is exactly the same below c:\\mlx so I am basically trying to move the whole directory tree to another location. please someone help me with either file my previous post I will add a link for on the next update.
@ARGV = qw(.) unless @ARGV; use File::Find; use File::Copy; use Data::Dumper; @dirs=(); my $dir="\\mlx\\"; find sub {move("$File::Find::name, -d","$dir.$_") or die "This didn't +work either"};
my previous attempt which is now giving me an error due to the path. //760926 not sure if this link will work. link does not work. from the book I was reading I thought -d was directory, example.. ok I fixed the problem with the move it was due to the directory I was calling it from, I was using a batch file, needed to do a chdir to the correct path apparently the script was looking at the current location, anyways I have it working now.
@ARGV = qw(.) unless @ARGV; use File::Find; find sub { print $File::Find::name, -d && "/", "\n" }, @ARGV;

Replies are listed 'Best First'.
Re: Move using File::Find
by Corion (Patriarch) on Apr 30, 2009 at 20:44 UTC

    This line:

    move("$File::Find::name, -d","$dir.$_")

    will try to move (for example) a file named foo.bar, -d to a file \mlx\foo.bar, -d. Are you really sure that you have files that have , -d at the end of their filename?

    Also, File::Find::find wants some directories to search, so you should give it some.

Re: Move using File::Find
by Anonymous Monk on Apr 30, 2009 at 22:07 UTC
    Its good that you've added error checking, but you need to do better. Something like
    my (@useful) = ( "$File::Find::name, -d", "$dir.$_" ); move(@useful) or die "ERROR: move(", map( {qq"($_)"} @useful ), ") failed: $!";

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2022-01-21 12:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (57 votes). Check out past polls.

    Notices?