Page 1 of 1

Posted: 06/12/03, 4:40 pm
by bob
Anyone got a perl script that takes all the files in a directory and writes them to a single file?

I know sounds easy, but I can't quire get it. Here's what I've got....

<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class=postbody>Code:</font><HR width=100% color=#333333 SIZE=1></TD></TR><TR><TD><FONT class=code><PRE>#!/usr/bin/perl -w


print "Content-type: text/htmlnn";


##############################

$databasefile = "/home/virtual/adeiu/munge.txt";

$dir = "/home/virtual/html/";

opendir(DIR,$dir);
@files = grep -f, grep /.txt$/i, map "$dir/$_", readdir DIR;


foreach $file (@files)
{

open (FILE,$file);



open (DBFILE, ">>$databasefile");

print DBFILE;
close FILE;

}
closedir(DIR);
close DBFILE;</PRE></FONT></TD></TR><TR><TD><HR width=100% color=#333333 SIZE=1></TD></TR></TABLE><!-- BBCode End -->


The problem I'm having is it just pulls a couple of the text files, not all of them..... What am I doing wrong here?


Edited to pull a couple of stupid mistaskes.



_________________
We were talking about the space between us all and the people who hide themselves behind a wall of illusion.....

<font class=editedby>[ This Message was edited by: bob on 2003-06-13 10:46 ]</font>

Posted: 06/12/03, 5:01 pm
by SOD
Tried a discussion group bob? What you wish to do is merge HTML files? There is probly a way. I know merge in other languages can be a tricky process...if you are using linux is there anyway to use bash to implement Merge? But you probly wish to implement this dynamically.

Posted: 06/14/03, 12:45 pm
by RedRage
duno bout perl but php:

exec("ls -1 > resultfile.txt");

Perl's exec is system() i think but i could be talking out my ass