Here is the detailed Problem statement and my approach:
config.txt contains 2 section DIR and FILE.
DIR has list of directory path and FILE section has file path
I need to read the file line by line and check if each line is a file
+or a directory.
It is required to copy the entire directory content to source director
+y.
Similarly mentioned file needs to be copied to source directory
I need to use robocopy to copy large files.The program is working for
+copying file but not for copying directory.
For this i thought to split the last part of directory path and attach
+ this to source path inorder to copy using robocopy.
the syntax of robocpy command is
robocopy $target_file $source_dir_mod ## here target_file=C:\shyam\di
+r1 and i need to get source_dir_mod=C:\sundar\directory1\dir1
Then I can copy dir1 to the source directory
[DIR]
C:\shyam\dir1
[FILE]
C:\shyam\output.txt
$\ = "\n" ;
$, = "\t" ;
#$|=1;
use strict;
use warnings;
use POSIX qw[ _exit ];
use MIME::Lite;
use Sort::External;
use Net::Ping;
use Win32::DriveInfo;
my $source_dir = `pwd`;#C:\sundar\directory
my $source_dir_mod;
my $file_config = "config.txt";
my $sym = '\\' ;
open FH_config, "$file_config" or die "$!";
while (my $line = <FH_config>)
{
chomp $line;
next if $line eq "";
if (($line eq "[DIR]") or ($line eq "[FILE]"))
{
#print "no action";
}
else
{
my $target_file = $line;
#print $target_file;
if (-d $target_file)
{
print("it is directory");
(my $path,my $file) = $target_file =~ m|^(.*[/\\])
+([^/\\]+?)$|;
$source_dir_mod = join '',$source_dir,$sym,$file;
print ($source_dir_mod);
`robocopy $target_file $source_dir_mod`;
#print "$path"; ##C:\shyam
#print "$file"; ##dir1
}
elsif(-f $target_file)
{
print("is a file");
(my $path,my $file) = $target_file =~ m|^(.*[/\\])
+([^/\\]+?)$|;
#print "$path"; ##C:\shyam
#print "$file"; ##output.txt
`robocopy \/Z $path $source_dir $file`;
}
else
{
print("no action");
}
}
}
close FH_config;
|