E
EddieJ
I'm writing my first perl script and I'm running in to
difficulties as I imagined. What I'm trying to do is
basically scan all the directories and subdirectories
of a drive for powerpoint files, write the full path
and name of the files to an ordinary text file, and
then remove the drive name and colon (eg C from the
path and send the output to another text file.
The script I have so far is...
print "Which drive do you want to search? ";
chomp($drive = <STDIN>);
chdir("$drive") || die "Cannot access requested drive";
$outputfile1 = ("%HOMEDRIVE%\\ppfile1.txt");
$outputfile2 = ("%HOMEDRIVE%\\ppfile2.txt");
$outputfile3 = ("%HOMEDRIVE%\\ppfile3.txt");
if (-e $outputfile1) {
unlink ($outputfile1);
}
if (-e $outputfile2) {
unlink ($outputfile2);
}
if (-e $outputfile3) {
unlink ($outputfile3);
}
system ("dir/s/b *.pp* >$outputfile1") && die "Cannot write to file1 $!";
system ("dir/s/b *.xyz >$outputfile2");
open FILE1, ">$outputfile1" || die "Cannot open file1 $!";
open FILE2, ">$outputfile2" || die "Cannot open file2 $!";
while (defined <FILE1>) {
# print FILE1 $_;
print FILE2 s/^a-zA-Z://;
}
close (FILE1) || die "Cannot close file1 $!";
close (FILE2) || die "Cannot close file2 $!";
But when I run it, the second output file is empty and perl
complains that it cannot close the first outputfile
-----------------------------
Which drive do you want to search? j:
File Not Found
Cannot close file1 Bad file descriptor at powerp.pl line 27.
-------------------------------
The "File Not Found" is from the
"system ("dir/s/b *.xyz >$outputfile2");"
which doesnt bother me since I'm just trying to create an empty
file so that I can open it later to receive the output (without
the C.
From what I can see though, the open commands aren't working
despite the use of the "die" commands..
So...I'm sure this is very obvious to anyone with experience
of Perl, but (a) what am I doing wrong with the script??? and
(b) is there a more efficient way of doing what I'm trying to
do??. Can you do a recursive directory search in perl without
using the system dir/b/s command, and should I store the output
in an array rather than the first output file....
Thanks in advance....
EJ
difficulties as I imagined. What I'm trying to do is
basically scan all the directories and subdirectories
of a drive for powerpoint files, write the full path
and name of the files to an ordinary text file, and
then remove the drive name and colon (eg C from the
path and send the output to another text file.
The script I have so far is...
print "Which drive do you want to search? ";
chomp($drive = <STDIN>);
chdir("$drive") || die "Cannot access requested drive";
$outputfile1 = ("%HOMEDRIVE%\\ppfile1.txt");
$outputfile2 = ("%HOMEDRIVE%\\ppfile2.txt");
$outputfile3 = ("%HOMEDRIVE%\\ppfile3.txt");
if (-e $outputfile1) {
unlink ($outputfile1);
}
if (-e $outputfile2) {
unlink ($outputfile2);
}
if (-e $outputfile3) {
unlink ($outputfile3);
}
system ("dir/s/b *.pp* >$outputfile1") && die "Cannot write to file1 $!";
system ("dir/s/b *.xyz >$outputfile2");
open FILE1, ">$outputfile1" || die "Cannot open file1 $!";
open FILE2, ">$outputfile2" || die "Cannot open file2 $!";
while (defined <FILE1>) {
# print FILE1 $_;
print FILE2 s/^a-zA-Z://;
}
close (FILE1) || die "Cannot close file1 $!";
close (FILE2) || die "Cannot close file2 $!";
But when I run it, the second output file is empty and perl
complains that it cannot close the first outputfile
-----------------------------
Which drive do you want to search? j:
File Not Found
Cannot close file1 Bad file descriptor at powerp.pl line 27.
-------------------------------
The "File Not Found" is from the
"system ("dir/s/b *.xyz >$outputfile2");"
which doesnt bother me since I'm just trying to create an empty
file so that I can open it later to receive the output (without
the C.
From what I can see though, the open commands aren't working
despite the use of the "die" commands..
So...I'm sure this is very obvious to anyone with experience
of Perl, but (a) what am I doing wrong with the script??? and
(b) is there a more efficient way of doing what I'm trying to
do??. Can you do a recursive directory search in perl without
using the system dir/b/s command, and should I store the output
in an array rather than the first output file....
Thanks in advance....
EJ