LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 01: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, 11:37 AM   #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



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 22 12-13-2019 05:20 PM
How are binary program files placed into a directory for installation? devonto Linux - Newbie 2 12-15-2006 09:26 AM
copy 3 files to a directory and all subdirectories? snip128 Linux - Newbie 9 08-12-2005 09:18 PM
copy files from directory to directory without subfile ALInux Linux - General 2 06-03-2005 11:51 AM
locate and copy files - without directory tree rodda Linux - General 1 01-16-2005 02:10 AM

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

All times are GMT -5. The time now is 08:49 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
Open Source Consulting | Domain Registration