R
Robin
This one's really got me stumped... the bbs files are "something.post" and
the reply files are "something2.something" the second something being the
name of the person who posted originally. What I'd like this script to do is
to remove all of the reply files that corospond to the original post file...
and when I run it it just deletes them all... I already understand why, but
how can I get this so it only deletes the corosponding files. Thanks. btw,
I'm doing this as a hobby, I study creative writing- some of my stories are
at http://www.reachcac.org/robin/stories.html
#!/usr/bin/perl
#admin.cgi for bbs.cgi v.1.0.1
require ('lib.cgi');
require ('authlib.cgi');
&data_cgivars;
$" = "";
$, = "";
&login ("bbs.cgi");
if ($FORM{'Logout'})
{
&logout ("bbs.cgi");
exit;
}
if (! ($FORM{'Submit'}))
{
&output ("Welcome to BBS Admin...");
exit;
}
if (! ($FORM{'del'}) && $FORM{'Submit'})
{
&output ("Please select a file!");
exit;
}
print ("Content-type:text/html\n\n");
opendir (BBSFILES, "BBSFILES/");
@files = readdir (BBSFILES);
closedir (BBSFILES);
foreach $file (@files)
{
if ($file ne "." and $file ne "..")
{
#opendir (BBSFILES, "BBSFILES/");
#@files2 = readdir (BBSFILES);
#closedir (BBSFILES);
unlink ("BBSFILES/$file") if ($file eq $FORM{'del'});
@sec = split (/\./, $file);a
if ($sec[1] ne "post")
{
$file =~ s/\..+//;
if (-e "BBSFILES/$file.$sec[1]")
{
unlink ("BBSFILES/$file.$sec[1]");
}
}
else
{ next; }
}
}
&output ("Your changes have been made!");
exit;
sub output
{
my ($output) = @_;
print ("Content-type:text/html\n\n");
print <<END;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>BBS ADMIN</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align="center">
<p><strong>BBS Admin</strong></p>
<p>$output</p>
<p>Delete Entries:</p>
<form action="admin.cgi" method="post">
<p>
<select name="del" size="7" id="del">
END
opendir (BBSFILES, "BBSFILES/");
@filesout = readdir (BBSFILES);
closedir (BBSFILES);
foreach $fileout (@filesout)
{
if ($fileout =~ /\.post/)
{
print ("<option value=\"$fileout\">$fileout</option>");
}
}
print <<END;
</select>
</p>
<p>
<input type="submit" name="Submit" value="Delete">
<input type="submit" name="Logout" value="Logout">
</p>
</form>
</div>
</body>
</html>
END
}
the reply files are "something2.something" the second something being the
name of the person who posted originally. What I'd like this script to do is
to remove all of the reply files that corospond to the original post file...
and when I run it it just deletes them all... I already understand why, but
how can I get this so it only deletes the corosponding files. Thanks. btw,
I'm doing this as a hobby, I study creative writing- some of my stories are
at http://www.reachcac.org/robin/stories.html
#!/usr/bin/perl
#admin.cgi for bbs.cgi v.1.0.1
require ('lib.cgi');
require ('authlib.cgi');
&data_cgivars;
$" = "";
$, = "";
&login ("bbs.cgi");
if ($FORM{'Logout'})
{
&logout ("bbs.cgi");
exit;
}
if (! ($FORM{'Submit'}))
{
&output ("Welcome to BBS Admin...");
exit;
}
if (! ($FORM{'del'}) && $FORM{'Submit'})
{
&output ("Please select a file!");
exit;
}
print ("Content-type:text/html\n\n");
opendir (BBSFILES, "BBSFILES/");
@files = readdir (BBSFILES);
closedir (BBSFILES);
foreach $file (@files)
{
if ($file ne "." and $file ne "..")
{
#opendir (BBSFILES, "BBSFILES/");
#@files2 = readdir (BBSFILES);
#closedir (BBSFILES);
unlink ("BBSFILES/$file") if ($file eq $FORM{'del'});
@sec = split (/\./, $file);a
if ($sec[1] ne "post")
{
$file =~ s/\..+//;
if (-e "BBSFILES/$file.$sec[1]")
{
unlink ("BBSFILES/$file.$sec[1]");
}
}
else
{ next; }
}
}
&output ("Your changes have been made!");
exit;
sub output
{
my ($output) = @_;
print ("Content-type:text/html\n\n");
print <<END;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>BBS ADMIN</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align="center">
<p><strong>BBS Admin</strong></p>
<p>$output</p>
<p>Delete Entries:</p>
<form action="admin.cgi" method="post">
<p>
<select name="del" size="7" id="del">
END
opendir (BBSFILES, "BBSFILES/");
@filesout = readdir (BBSFILES);
closedir (BBSFILES);
foreach $fileout (@filesout)
{
if ($fileout =~ /\.post/)
{
print ("<option value=\"$fileout\">$fileout</option>");
}
}
print <<END;
</select>
</p>
<p>
<input type="submit" name="Submit" value="Delete">
<input type="submit" name="Logout" value="Logout">
</p>
</form>
</div>
</body>
</html>
END
}