Hi,
I use the below code to move files from a specified directory as a command line argument to another directory, but this script fails when recursing into subdirectories.
I guess we have tweak the $file =~ s/\//\\/;
Can anybody hlp please? i have given the sample o/p below.
use strict;
use File::Find;
use warnings;
my @files = ();
my @dirs = @ARGV or die "Please supply a valid directory to search";
print "\n All contrib and keep Files within the specified directory will be moved recursively to D:\\jude-test \n";
find(\&move, @dirs);
print "\n Moving .contrib and .keep files to D:\\jude-test \n";
for my $file ( @files ) {
$file =~ s/\//\\/;
print "Moving $file to D:\\jude-test\n";
system("move $file D:\\jude-test");
}
print "\n";
sub move {
if(-f && m/\.(contrib|keep)$/) {
push @files, $File::Find::name;
}
}
O/P:
Moving f:\temp\ument.keep to D:\jude-test
1 file(s) moved.
Moving f:\temp\test/4Document.keep to D:\jude-test
The system cannot find the path specified.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.