LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-06-2008, 02:24 PM   #1
lnx_learner
LQ Newbie
 
Registered: Dec 2007
Posts: 1

Rep: Reputation: 0
Smile How can I use Linux to copy binary files to a new directory


Hi,
I am new to Linux and Perl as well. I wrote a Perl script that compares two files (one is a text file and the other has images (.gif) in it. If an image in file 2 has an ID that's found in file one, I want to copy the image in a new directory with this textfile name. I am not being successful in copying and if anybody can help, I would appreciate it. When I try to print the output, images are printed as strings instead of binary. I am sure that there must an easy way to do this with Linx commands but I am not there yet. Here is my code:


#!/usr/bin/perl
use warnings;
use Getopt::Long;
use File::Copy;

my $output= "/data/Outputfile";
$filewith_images ="/data/Images/";
$textfile="/data/121test";

opendir (OUT, $output)or die " Can't open the output file";

open (FC,$txtfile) || die "Can't open the text file";
@image_desc = <FC>;

foreach $code(@image_codes)
{
opendir (FI, $filewith_images) or die " Can't open the file with images";
@images=grep(~/\_GIF$/i,readdir(FI)) or die " Can't ready directory";
foreach $item (@images)
{
$code++;
my $code1= substr($item, 0, -4);
if ($code1 eq $code){
print OUT "$item\n" ;
}
}
}
 
Old 01-07-2008, 12:37 PM   #2
Poetics
Senior Member
 
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 1,181

Rep: Reputation: 49
I believe it's the way 'print' handles data, and how you're requesting it be sent to the screen. I don't know if perldoc print has any further information on the subject, but I bet it'd be a good place to start -- are you just trying to print to the screen? It may be better to call a program to print them instead of relying on 'print' which may be much more limited. If you don't need to wait for output, perhaps an exec() instead of system()
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you copy hidden files from one directory to another? Akhran Linux - Newbie 19 12-29-2011 04:31 AM
How are binary program files placed into a directory for installation? devonto Linux - Newbie 2 12-15-2006 10:26 AM
copy 3 files to a directory and all subdirectories? snip128 Linux - Newbie 9 08-12-2005 10:18 PM
copy files from directory to directory without subfile ALInux Linux - General 2 06-03-2005 12:51 PM
locate and copy files - without directory tree rodda Linux - General 1 01-16-2005 03:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration