I wrote this script to take a directory of text files and append them 
into one BBEdit text file. I get comma separated files generated from 
our webserver and flow them into a Quark XPress template using Xdata 
variable data Xtension. At first I either had to copy and paste all the 
entries into one document or flow them each individually. But to make 
the flow in process more efficient I wanted to get all the text into one 
document. I used unlink to make sure the Appendedtext.txt didn't already 
exist in the folder (from rerunning the script). If it did unlink would 
delete it first. Any suggestion for making this script better?I'm still 
pretty new at PERL.

#! perl -w
use strict;
require "StandardFile.pl";

my $dir = &StandardFile'GetFolder("Select a folder to append files 
in","::");
my $line;
my $line2;
my @list;
my $outfile;
$outfile = "$dir".":"."Appendedtext.txt";
unlink ($outfile);
opendir(DIR, "$dir"); # read into array the directories within the 
destination directory
my @destDir = readdir(DIR); #assign to array the directories
closedir (DIR);
foreach my $destDir (@destDir) {
push my (@newfiles), "$dir".":"."$destDir";
open(OUT, ">>$dir".":"."Appendedtext.txt");
foreach my $newFile(@newfiles){
open(FILE, $newFile) or die "can't open file: $!";
while(<FILE>){
print OUT $_;
}
}
}
MacPerl::SetFileInfo('R*ch', 'TEXT', $outfile);

Reply via email to