To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.off-topic.geekOpen lugnet.off-topic.geek in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Off-Topic / Geek / 5090
5089  |  5091
Subject: 
Re: perl file copy question
Newsgroups: 
lugnet.off-topic.geek
Date: 
Wed, 5 Oct 2005 22:04:22 GMT
Viewed: 
2450 times
  
In lugnet.off-topic.geek, Ross Crawford wrote:
In lugnet.off-topic.geek, Larry Pieniazek wrote:
I have a need from within a perl module to copy a large (and variable, it's
wildcard driven) number of files from one directory to another. TMTOWTDI of
course. What's the best way under the following constraints?

- the OS is linux
- The wildcard varies from run to run so it's going to need to be a variable
(that seems like no big deal at all just mentioning it)
- I want to avoid system() or backtick, as I do not want to spawn a subprocess,
too expensive in the context I am in
- I prefer not to schlep around with digging up filenames and separating them
from the directories from what glob returned
- I prefer to use only standard perl and the default module set, not stuff I'll
have to install, getting stuff installed is a major pain (it took months to get
DBI and DBD onto the production systems)


I thought of using glob($wildcardExpression) to get an array of filehandles and
then using File::Copy but where I broke down there is that copy wants two
filehandles or file names and the target names aren't individually known,
necssarily, unless I dug into the filehandle to find the name, then separated
the directory off or something.

Try File::NCopy (although I dont think it's a standard module) -
http://search.cpan.org/~gabor/File-NCopy0.32/lib/File/NCopy.pm

Note however that you can easily obtain directory and filename from the path
string - you don't need the file handle (I'm pretty sure File::Basename is
standard):

use File::Basename;

$fullname = "/usr/local/src/perl-5.6.1.tar.gz";

$file = basename($fullname);
# file="perl-5.6.1.tar.gz"

$dir = dirname($fullname);
# dir="/usr/local/src"

This is something that seems easy in .sh or .ksh. I bet it's easy here too I'm
just not finding it, although I have been reading docs and searching for it for
a while.

It is easy - if you're able to call the OS. The OS is, after all, designed as a
program for handling files. But without that as an option, it becomes harder.

HTH

ROSCO

that does help! (meanwhile I got a version working that uses system(), just as a
stopgap...)

However I really don't want to use system() (or any process spawning things) and
since I want to wildcard aren't I going to have to use glob() to get an array of
filehandles? However,

http://perldoc.perl.org/functions/glob.html

says glob returns a list of filename expansions... do they mean names rather
than handles? If so, then ya, all set.



Message has 2 Replies:
  Re: perl file copy question
 
(...) Does this code help? It shows the outputs. Decided to have a fiddle with what Ross posted to see what everything did. Tim use File::Glob ':glob'; use File::Basename; $ddn="destination directory"; @t=(<g:/docs/in_prog...bes/*.*>); foreach $f (...) (19 years ago, 5-Oct-05, to lugnet.off-topic.geek)
  Re: perl file copy question
 
(...) Yes, it returns a list of filename strings, including any relative path. ROSCO (19 years ago, 5-Oct-05, to lugnet.off-topic.geek)

Message is in Reply To:
  Re: perl file copy question
 
(...) Try File::NCopy (although I dont think it's a standard module) - (URL) however that you can easily obtain directory and filename from the path string - you don't need the file handle (I'm pretty sure File::Basename is standard): use (...) (19 years ago, 5-Oct-05, to lugnet.off-topic.geek)

5 Messages in This Thread:


Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR