Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copying files from CD-ROM drive to C:/ Drive 1

Status
Not open for further replies.

vcherubini

Programmer
May 29, 2000
527
US
Hello:

I have a question about copying files.

I have many CD's full of files with a certain extension. I want to search the CD's, each directory and their subdirectories, for all files with the extension .lwo and then copy the file to a folder called Temp on my C:/ drive.

How would I do this?

I have some code that I have written, but it does not work:

[tt]
use File::Copy;
$i=0;
sub g {
foreach (glob "$_[0]/*") {
-d && g($_) unless -l;
opendir(D,"$_[0]");
while ($file = readdir(D)) {
#print "$file\n";
#getc;
if (($file eq ".") || ($file eq "..")) {
# do nothing
} else {
if ($file =~ m/\w+.?\w\.lwo/gi) {
copy("$file","$file");
}
}
}
close(D);

}
}
g("F:");
[/tt]

This, however, does not work. Can anyone shed some light?

Thanks,

-Vic vic cherubini
vikter@epicsoftware.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director
====
 
I think the problem with your program is that you don't need the readdir. The glob will return all of the files in the directory anyway, and you are calling opendir and readdir for things that are not directories. Perhaps the problem is that you expect glob(F:/*) to return only directories like a dir F:\* might?

Here is a modified version of your code that seems to work for me. It looks for bmp files in my c:/corel directory and just prints out the copy instead of performing the copy.

Code:
sub g {
	foreach (glob "$_[0]/*") {
		# recurse into subdirectories
		-d && g($_) unless -l;
		# if file ending in desired extension
		if (-f && /.bmp$/i) {
			# get filename portion of file (remove up to final /)
			# to use as destination
			$dest = $_;
			$dest =~ s/.*\///;
			$dest = "C:/TEMP/$dest";
			print "copy($_, $dest)", "\n";
		}
	}
}

g("C:/COREL");
 
I should have escaped the '.' when I was looking for a .bmp extension. Sorry.


if (-f && /\.bmp$/i) {

 
Sackyhack:

Thanks a bunch for that. It worked perfectly.

-Vic vic cherubini
vikter@epicsoftware.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director
====
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top