Firefox 16, a treat for developers http://t.co/cnd27CzT
Copy files or directories in Perl programming
This script will give a example how to copy files of directory of with specific paterns
This script presented by Patrick Lapre a member of Unixmen community from Netherlands
if You have any comment or suggestion . contact us from the unixmen Forum
#!/usr/bin/env perl
# Use serveral modules
use warnings;
# Comes in handy for debugging the script
use Data::Dumper;
use File::Copy;
# Define some variables to be used in the script
# A from path and to path are defined
my $from_path = “/Users/carllapre/test/from”;
my $to_path = “/Users/carllapre/test/to”;
# A variable to be used in the foreach loop later on
# An iterator
my $file = “”;
# Define the from location. This is the way the copy
# command works
my $file_new = “”;
my $file_loc = “”;
# A simple array to fill with the info read from
# the directory
my @array = ();
# To open a directory to be read, a stream is created
opendir(TO,$to_path) || die “Can’t open $to_path: $!”;
# To open a directory to be written to, a stream is created
opendir(FROM,$from_path) || die “Can’t open $from_path: $!”;
# A bit tricky. I’m using a grep-function to get the right files
# I’m looking for files, which have the pattern rbs or RBS
@array = grep(/rbs|RBS.*/,readdir(FROM));
# Just a debug tool
print Dumper(@array);
# Whoa the main loop!!!
foreach $file (@array) {
# Create a condition
$file_new = “$to_path/$file”;
# the -e option indicates if a file is existing in the defined directory
if (-e $file_new ) {
print “$file already exists in location $to_pathn”;
}
else {
print “Trying to copy $file to location $to_pathn”;
# this function copies each file to its destination
copy(“$from_path/$file”,”$to_path/$file_loc”) || die “Copy failed: $!”;
}
}
# You must close the streams in the end
closedir(FROM);
closedir(TO);
##############################################################################################
#you have any comment of suggestion please let us now
###########################################################################################
Like us on Facebook
This week Top Posts 
Top Things to do After Installing Ubuntu 13.04 ‘Raring Ringtail’ : Ubuntu 13.04 Raring Ringtail final is almost out. The final release it scheduled for release on Apri...0 comment(s) |
Howto: Upgrade to Ubuntu 13.04 Raring Ringtail from 12.04, 12,10 | Desktop & Server : Updated 05-04-2013: Ubuntu 13.04 Raring Ringtail will be released Soon, If you have ubuntu 12,10, 12...0 comment(s) |
Unix/Linux File Recognition. Did You Know? : Did you know that Unix and Linux has no concept of a file extension? What is a file name extension?
...0 comment(s) |
Install lamp with 1 command in Ubuntu 12.10, 13.04 Raring Ringtail & LinuxMint13 : Updated: 10/09/2012 :LAMP (Linux, Apache, MySQL and PHP) is an open source Web development platform ...0 comment(s) |
Howto- Resolve nosound problem on Ubuntu 13.04 Raring Ringtail,12.10 and Older : Updated 05/04/2013 : One of the common issues facing Ubuntu users after installing or upgrading Ubun...0 comment(s) |
Configure conky-Lua in Ubuntu (12.10 & 13.04 Raring Ringtail), Fedora, debian and LinuxMint | Howto Conky : Updated 05-04-2013: Conky is a free, light-weight system monitor for X, that displays any informatio...0 comment(s) |
Recent Posts
- Unix/Linux File Recognition. Did You Know?
- Migrate from MySQL to MariaDB in FreeBSD
- Connect Your Android Galaxy Tablet to Ubuntu via USB
- ElementaryOS Beta 1 and 2 Comparison and Review
- Introduction to the Linux Command Line
- A Secure Password
- Linux Kernel 3.10. It’s BIG!
- Monitoring Users Activity Using psacct or acct Tools in Linux
- Run Your Own Social Network Using elgg on RHEL / CentOS and Scientific Linux
- Getting Debian 7.0 ‘Wheezy’ Up and Running
Recent Comments



















SK
| #
I am working on it. Stay tuned. Thanks for the comment.
adriana rizzati
| #
You are right, I saw them just now and they are awesome!
SK
| #
Thanks for the comment Abdullah. Stay tuned with us always.
Abdullah Musazai
| #
Thank you for such a great service you always do, hope you gain more power and more energy to work more & more
Dominik Bauer
| #
thx a lot!