How to use command line to copy file in window?

Method1:

@echo off
For /f “tokens=2-4 delims=/ ” %%a in (‘date /t’) do (set mydate=%%c-%%a-%%b)
For /f “tokens=1-2 delims=/:” %%a in (‘time /t’) do (set mytime=%%a%%b)
set backup_time=%mydate%_%mytime%
echo %backup_time%
REN “E:\TestLink\xampplite_mantis_testlink\mysql\data\testlink” “testlink_%backup_time%”
ROBOCOPY “\\10.207.218.133\ADS Builds Temporary\TestLink\testlink” “E:\TestLink\xampplite_mantis_testlink\mysql\data\testlink” /MIR

Method2:

use strict;
use Cwd;
my $product = @ARGV[0];
my $build_name = @ARGV[1];
my $os = @ARGV[2];
if (($product eq "")||($build_name eq "")||($os eq ""))
{
	print "\n\n----------ERROR------";
	print "\n\n----------Plese provide FULLY 3 aguments : 1.product (ex: arm), 2. build_name (ex: b161115), 3. os (ex: win)------\n\n";
	print "\n\n----------Plese provide FULLY 3 aguments : 1.product (ex: arm), 2. build_name (ex: b161115), 3. os (ex: win)------\n\n";
	print "\n\n----------Plese provide FULLY 3 aguments : 1.product (ex: arm), 2. build_name (ex: b161115), 3. os (ex: win)------\n\n";
	die;
}
my $cmd = "find '\\\\\\10.207.218.117\\ADS Server\\ADS\ Builds\\Builds_for_ARM' -type f -print | grep -i ";
if (uc ($product) eq "ARM")
{
	print "product name ok.....\n";
	$cmd = "find '\\\\\\10.207.218.117\\ADS Server\\ADS\ Builds\\Builds_for_ARM' -type f -print | grep -i ";
}
elsif (uc ($product) eq "E200")
{
	$cmd = "find '\\\\\\10.207.218.117\\ADS Server\\ADS\ Builds\\Builds_for_E200' -type f -print | grep -i ";
}
elsif (uc ($product) eq "VISION")
{
	$cmd = "find '\\\\\\10.207.218.117\\ADS Server\\ADS\ Builds\\Builds_for_Visions' -type f -print | grep -i ";
}
else
{
	print "\n\n----------ERROR------";
	print "\n\n----------Product name : $product is not correct, it should be 'arm', 'e200', 'vision' \n";
	print "\n\n----------Product name : $product is not correct, it should be 'arm', 'e200', 'vision' \n";
	die;
}

if ((uc ($os) =~ /WIN/))
{
	print "os name ok.....";
	$cmd = $cmd."'.exe' > testcopybuilds.txt";
}
elsif (uc ($os) =~ /LINUX/)
{
	print "os name ok.....";
	$cmd = $cmd."'.bin' > testcopybuilds.txt";
}
else
{
	print "\n\n----------ERROR------";
	print "\n\n----------OS name : $os is not correct, it should be 'win', 'linux' \n";
	print "\n\n----------OS name : $os is not correct, it should be 'win', 'linux' \n";
	die;
}
print "\n\n----------cmd: $cmd-------\n\n\n";
system($cmd);
my @all_builds = read_file_to_array("testcopybuilds.txt");
unlink "testcopybuilds.txt";
my $signal_arm_win="\/S32";
my $signal_window=".exe";
my $signal_linux=".bin";

foreach my $element (@all_builds)
{
	my $check = substr $element, -11;
	if (uc ($check) =~ uc ($build_name))
	{
		my $temp_element = uc $element;
		my $temp_signal = uc $signal_arm_win;
		my $offset = 0;
		my $result = index($temp_element, $temp_signal,$offset);
		  while ($result != -1) {

			print "Found $temp_signal at $result\n";

			$offset = $result + 1;
			$result = index($temp_element, $temp_signal,$offset);
		  }

		$result = index($temp_element, $temp_signal,$offset-1);
		my $folder = substr $element,0,$result;
		my $file = substr $element,$result+1;
		print "----------Result: $result-------\n";
		print "----------Folder: $folder-------\n";
		print "----------File: $file-------\n";
		my @temp_file = split(/$signal_window/,$file);

		$file = @temp_file[0].".exe";
		if (uc ($os) =~ /LINUX/)
		{
			my @temp_file = split(/$signal_linux/,$file);
			$file = @temp_file[0].".bin";
		}
		if (length(@temp_file[1]) > 0)
		{
			print "----------Error: There is something wrong with the file name of the file : $file in the server. Please rename it-------\n";
			print "----------Error: There is something wrong with the file name of the file : $file in the server. Please rename it-------\n";
			print "----------Error: There is something wrong with the file name of the file : $file in the server. Please rename it-------\n";
			print "----------Error: There is something wrong with the file name of the file : $file in the server. Please rename it-------\n";
			print "----------Error: There is something wrong with the file name of the file : $file in the server. Please rename it-------\n";
			print "----------Error: There is something wrong with the file name of the file : $file in the server. Please rename it-------\n";
			print "----------Error: There is something wrong with the file name of the file : $file in the server. Please rename it-------\n";
			print "----------Error: There is something wrong with the file name of the file : $file in the server. Please rename it-------\n";
		}
		print "----------Folder: $folder-------\n";
		print "----------File: $file-------\n";
		my $currpath = cwd();
		my $copybuild = "ROBOCOPY \"$folder\" \"$currpath\" \"$file\"";
		print "--------command: $copybuild \n";
		print "-----------------\n";
		my $res = system($copybuild);
		print $res."\n";
		if ($res > 0)

		{
			print "Copied successfully \n";
			print "Copied successfully \n";
			print "Copied successfully \n";
			print "Copied successfully \n";
			print "Copied successfully \n";
		}
		else
		{
			print "Failed !Failed !Failed !Failed !Failed !Failed !\n";
			print "Failed !Failed !Failed !Failed !Failed !Failed !\n";
			print "Failed !Failed !Failed !Failed !Failed !Failed !\n";
		}
	}
	else
	{
			print "Other build: $$element !\n";
	}

}

sub read_file_to_array
{
my $source_file = shift;
my @array1 = ();
open(FILE, "<", $source_file) || die "cannot open < $source_file: $!";
	foreach()
	{
		chomp($_);
		push @array1,$_;
	}
close(FILE);
return @array1;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s