Google Answers Logo
View Question
 
Q: File Copy Program ( No Answer,   2 Comments )
Question  
Subject: File Copy Program
Category: Computers > Programming
Asked by: paxon-ga
List Price: $2.50
Posted: 17 Sep 2004 11:52 PDT
Expires: 17 Oct 2004 11:52 PDT
Question ID: 402588
I am looking for the following computer program, A dos Batch File, or
PHP code that will do the following.

It will scan though directory "A" and all of "A" sub folders. Each
file it finds in the directory "a" and subfolders it will search for that
same file name in another Directory "B" and sub folders
If it finds the File in Dirtory "b" or any sub folder of directory "B"
it copies the file from from Directory "A" path to Directory "B" path only if
the file is newer in directory "A"

Request for Question Clarification by leapinglizard-ga on 17 Sep 2004 13:20 PDT
I could write a Python script to do that for you, but you would need
to have the Python interpreter installed in order to run the script. A
free download is available for Windows and all other platforms.

Download Standard Python Software
http://python.org/download/

Furthermore, I don't think the current price of your question is
commensurate with the amount of effort it would take to write such a
script. If you find that your question remains unanswered after some
time, you might like to consider raising the price in order to attract
the attention of more Researchers.

leapinglizard

Clarification of Question by paxon-ga on 28 Sep 2004 10:59 PDT
These answers are very close. But as each file is copied, the source
path may be differnt then the destination path. for examaple. file
"test.txt" in the soruce path C:\data\ need to scan though all sub
directories in "d:\path\" and find "Test.txt and replace it. So the
destination folder may be d:\path\here, or it may be d:\path\here2 or
d:\path\here3.
Answer  
There is no answer at this time.

Comments  
Subject: Re: File Copy Program
From: fornn-ga on 22 Sep 2004 00:38 PDT
 
<?
/*----------------- Put your path here --------------*/

$path_a="/app8/www2";		
$path_b="/app8/www";	

/*---------------------------------------------------*/

function listDir($path){	
	global $fileinfo,$dirinfo;
	//which file or directory you don't want update,please type here
	$seekFile=array(".","..","lost+found",".kde");	

	if(!file_exists($path)){
		die("'".$path."'directory is not exists \n");
	}
	
	$handle=dir($path);
	while ($entry = $handle->read()) {
		if(in_array($entry,$seekFile)){
			continue 1;
		}

		$f=$path."/".$entry;
		if(is_dir($f)){
			$dirinfo[$f]=1;
			listDir($f);
		}else{
			$filetime=filemtime($f);
			$fileinfo[]=array(
				'path'=>$path,
				'name'=>$f,
				'time'=>$filetime				
			);

			//echo $filetime." - ".$f."<br>";
		}
	}
}

function copyFile($path_from,$path_to){
	global $fileinfo,$dirinfo;
	
	//Check Directory 
	if(!file_exists($path_from)){
		die("'".$path_from."'directory is not exists \n");
	}	
	
	//Check directory
	if(!file_exists($path_to)){
		die("'".$path_to."'directory is not exists \n");
	}

	//Create all directory if not exists
	while(list($key,$val)=each($dirinfo)){
		$new_path=ereg_replace("^".$path_from,$path_to,$key);
		if(!file_exists($new_path)){
			echo "Create directory: ".$new_path."\n";
			mkdir($new_path,0777);
		}
	}

	
	//Start Copy File
	while(list($key,$val)=each($fileinfo)){
		$src_name=$val['name'];
		$src_time=$val['time'];
		$new_name=ereg_replace("^".$path_from,$path_to,$src_name);	
		
		if(file_exists($new_name)){
			if($src_time>filemtime($new_name)){
				unlink($new_name);				
				copy($src_name,$new_name);
				echo "updated file: $new_name \n";
			}
		}else{
			echo "copy file to $new_name \n";
			copy($src_name,$new_name);
		}
	}	
}

echo "<pre>\n";

$fileinfo=array();
$dirinfo=array();
listDir($path_a);
copyFile($path_a,$path_b);

echo "\n</pre>";

?>
Subject: Re: File Copy Program
From: kool420m-ga on 26 Sep 2004 18:18 PDT
 
You can use xcopy command with /D tag
xcopy (A Path...)\*.*  (B Path...)\*.* /D

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy