Im trying to get perl look in a folder and print to the screen all the file names located in that folder. Is this posible, if not how can I get this done????
$folder=$fullfilepath;<br>opendir (FOLDER, $folder) ¦¦ die "Unable to open your folder.";<br>@filenames= readdir(FOLDER);<br>closedir(FOLDER);<br><br>This is what I use for a member utility. The files in that directory will be read into the array @filenames. Then you can simply use a foreach loop to print each filename to the screen. You could add <br><br>open(FILE,$file);<br>$size= -s FILE;<br><br>inside the loop to print out the size of each file too.<br><br>
thanks a lot but I went out to buy a Perl book and I already got it done. However, I would like to know how to put this code inside a html to make it viewable on the web.<br><br>So when i click on a link, it "prints" those filenames to the webpage....
How about a link to the script? You'll need some way of specifying the path of the directory to show if want to display more than one. I think that should work shouldn't it? You might need to use the full path to the script...<br><br>Or as an input on a form, when users hit the "submit" they start the script. You could then use a hidden input from each page to pass the script the directory to open and read it from $ENV.<br><br>e.g.<br><FONT FACE=monospace><br><a href="scriptname.pl">Click me to see directory files</a><br><br><form method=post action="myscript.pl"><br><input type=hidden name=dirtoopen value="/users/home/loon"><br></font><br><br>Hope that helps<br>Loon
yeah but when I do this <br>(<a href="scriptname.pl">Click me to see directory files</a><br>it simply spits out the contents of the perl file. the thing is I want it to display the directory files in a particular table cell. So when I click on the link it simply shows the directory file names in that cell. Do I have to write the whole html file in perl, "printing" out all the html tags eg. (print "<html>" and so on...? Or is there an easier way of doing so? Thats what I'm looking for an easier way... cause I already have the html file created I just want to run this damn script and have it show in a particular table... HELP!!!!!!!!!!
I would rewrite the whole page so that it is a perl CGI script, using perl to output all of the required HTML tags. To make things <i>real</i> easy, I would use the CGI module that comes with perl. You create a new CGI object that is your page. Then, when you want to print some HTML you use the CGI objects functions to print it. For example, instead of "print '<B>some text</B>'", instead you can "print $MyCGI->bold('some text')". If you want to print the HTML header, you "print $MyCGI->header". It makes things very easy.<br><br>Otherwise, it sounds like what you are saying is "I have a table displayed. I want to click a link and update the table displayed on the current page with the file listing". As discussed in another thread, you can't do this... The solutions offered so far will replace your current page with the output from the CGI script.<br><br>So, I'd rewrite the whole page in perl. In the long run, you are going to see a lot of benefits.<br><br>Before you do, though, you need to set up your web server so that it executes perl programs (with a .pl extension) instead of passing the contents of the script to the browser. What web server are you using? <p> <br><a href=mailto: > </a><br><a href= > </a><br>--<br>
0 1 - Just my two bits
ok SO you're saying that theres no way to do it without rewriting the the page. Ok then I guess I'll have to do it that way then, I was just trying to avoid doing that. But I guess I'll have to, thanks. Im using IIS for my web server...<br><br><br>thanks again
You have another dangerous option. You could make the directories you are interested in sub-directories of your web server root dir. And, don't put any index.html files in the sub-dirs. The browser will then simply display the files in each sub-dir. Be aware that this gives your user public a lot of info about your server. <b> I would not do it that way</b> unless I had a very small and trustworthy user community. <br><br>My vote, follow AndyBo's advice and rewrite the page with CGI.pm. You'll get a big bang for the investment buck spent on doing that. <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.