Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Urgent!  :)  Reading a Directory of Files

Posted on 1998-10-29
6
Medium Priority
?
238 Views
Last Modified: 2010-03-04
Hello!

How do I impliment the following in my CGI program?

I've got a directory full of .htm files. (and only .htm files)
How do I make my program:
A. Show each one on the screen (all at the same time) in the order they were posted to the directory.
B. Make it possible to delete specific ones. (via a 'delete' button on the page the cgi creates.

Thanks a bunch!
Please hurry your answer.
-Mark
0
Comment
Question by:eversoslightly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 2

Expert Comment

by:shchuka
ID: 1205804
You should use the opendir function, something like this, for example:

#!/usr/bin/perl
print "Content-type: text/html\r\n\r\n";

opendir(DIR,"/rootdir/mydir");
while($file = <DIR>) {
    print "$file <form method=GET action=delete.pl?$file><input type=submit value='Delete'></form><br>\n";
}
closedir(DIR);

Also, you'll have another file, delete.pl, like this:

#!/usr/bin/perl
unlink $ARGV[0];

You might need to modify this a little to accomodate correct subdirectories and also incorporate error handlers.

Hope this helps,
-Aleks

0
 
LVL 1

Author Comment

by:eversoslightly
ID: 1205805
Thanks a lot - but something isn't working.

#!/usr/bin/perl
print "Content-type: text/html\r\n\r\n";

opendir(DIR,"/rootdir/mydir");
while($file = <DIR>) {
    print "$file <form method=GET action=delete.pl?$file><input type=submit value='Delete'></form><br>\n";
}
closedir(DIR);
  Here is the code you gave me for my one file... I modified the parts that needed to be modified, such as the path.
It appears that you need $file to equal something.... $file doesn't = <DIR> Or something - I'm not sure.... but when I call it, even though there are files in the directory, its not showing any of them when I call the program.
Can you help me any further?  Thanks a lot....

I'm going to have to reject this for now, so others are able to see the question.
0
 
LVL 1

Author Comment

by:eversoslightly
ID: 1205806
Thanks a lot - but something isn't working.

#!/usr/bin/perl
print "Content-type: text/html\r\n\r\n";

opendir(DIR,"/rootdir/mydir");
while($file = <DIR>) {
    print "$file <form method=GET action=delete.pl?$file><input type=submit value='Delete'></form><br>\n";
}
closedir(DIR);
  Here is the code you gave me for my one file... I modified the parts that needed to be modified, such as the path.
It appears that you need $file to equal something.... $file doesn't = <DIR> Or something - I'm not sure.... but when I call it, even though there are files in the directory, its not showing any of them when I call the program.
Can you help me any further?  Thanks a lot....

I'm going to have to reject this for now, so others are able to see the question.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:eversoslightly
ID: 1205807
Gerrr... I accidentally hit the button twice :)
0
 
LVL 2

Accepted Solution

by:
shchuka earned 200 total points
ID: 1205808
I'm sorry, I confused reading a directory with reading a file.  The correct line should be:

while($file = readdir(DIR)) {
    print ...
}

Hope this works,
-Aleks.
0
 
LVL 1

Author Comment

by:eversoslightly
ID: 1205809
Thanks a lot!

This really helped, and worked well.

-Mark
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question