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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy a file from the list of files in a folder to another folder.

Status
Not open for further replies.

npds201

Technical User
Jun 5, 2012
1
0
0
US
Hi,

I have written a code for coping the Chrome 'Bookmarks' file to another folder of my system's D drive. Everything works fine but unable to copy the file. Here is the code. Please suggest me where is the problem. I am absolutely new to perl.


use strict;
use warnings;
use File::Copy;

my $src = 'C:\Documents and Settings\npds\Local Settings\Application Data\Google\Chrome\User Data\Default';
my $dst = 'D:\MyDoc\MyFab\Chrome';

opendir(DIR,"$src") or die "Cannot open : $src\n";
my @files = readdir(DIR);
closedir(DIR);

my $a = $files[4]; # This is for the file 'Bookmarks'.
copy($a,$dst) or die "Error coping file : $a\n";

Thanks in advance.
npds
 
$files[4] is a very unreliable way to identify the Bookmarks file. What happens when a Chrome update creates some new directory or file in there called "Aardvark" for example? Why are you bothering to opendir and so-on... you already know what the file is called.

Your source in the copy command needs the full path.

Your destination in the copy command needs the full path including the destionation filename, not just a directory name.

Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top