• Perl Script For Listing Files

    Author
    Topic
    #374582

    I’m in the midst of what could turn out to be a long (Google) search for an available Perl script. My domain is hosted by a company which has my account on a Windows 2000 server. I would like to create a “public” directory on my site which, when accessed by any user, would list ALL the files in that directory. They could be graphics, text, zip files, etc. I just want a visitor to be presented with an “FTP-like” list so he/she could view or download from this directory. I don’t know anything about programming, but the host company tells me you can’t do it on Win2000 with permissions, you have to use a (xxxxx.pl) script.

    While I’m searching (and there’s LOTS of places to look at!) does anyone have a suggestion for such a script? I’m not afraid to do modifications to change the directory name, or like that. Thanks for thinking ’bout me!

    Viewing 1 reply thread
    Author
    Replies
    • #606371

      Hi Al,

      I’m not really into Perl, but I believe this can easily be done with an ASP page. This will work on your host since it is Windows 2000.

      I’m headed out the door for a meeting now, but I’ll try to get something together for you later today – if you don’t find a solution before then.

      My idea is to use the FileSystemObject scripting component to make a list of files in the directory.

      Until then….

      • #606373

        Mark, correct me if I’m wrong, but if the host company doesn’t have the ASP extension enabled or allowed, won’t that cause problems? I know that my hosting company requires an email at the very least to enable additional file extensions (might be worth having done anyway, Al).

        • #606374

          Thanx for the tip. I’ll check their pages and/or send them a note asking about ASP.

      • #606376

        Thanks to BOTH Marks for replying and asking. Looks like I’m OK….. but I’m going to ask them if it has to be “enabled” for my account.

      • #606650

        A question for MarkJ: I’ve searched so much my eyes hurt! . compute

        BUT, I’d like to solicit your opinion on this link.

        Since I know nada about ASP or Perl, do you think this code will do the job I’m looking for? Sorry to impose on your time, but I’d really appreciate your opinion.

        • #606703

          HI Al,

          I’m sorry for not being able to finish that code for you. I kept running into some problems on my local server when using the FileSystemObject. I believe that Norton Antivirus blocked the use of the Scripting object because it thought it was being used for malicious purposes (hardly!)…

          The link you posted does exactly what I was trying to do (except it looks better). That’s definitely the way to go. I would probably add a few lines of code to exclude ASP and HTM(L) files just because your users don’t realy need to download those. (See attachment) I also made a few tweaks to the way the current folder name is acquired. When running on my local webserver, this made the difference between working and not working.

          Great searching – you’ve definitely found a winner!

          Note: As I try to use the sample on my web host, it will not display. I’ll have to check the settings to see if any necessary permissions are disabled for some reason. I was finally able to run the code on my local computer with a few modifications.

          Hope this helps!

          Update: I got the file working on my server after tinkering with the permissions (using my web host’s web-based control panel). I assigned full control to the System user which did the trick. Yipee! joy

          • #606717

            Hallelul-Ya! What a wonderment you are, MR. Mark!

            I uploaded the showfilelist.asp into the folder on my server and it works EXACTLY as you described! THANK YOU so much for the boost.

            As I asked in my PM I sent you, how does one get an ASP file to execute automatically, without having to have the user include it in the URL they enter? Should I make up an INDEX.HTML with an “onload” command, or what?

            See what THE LOUNGE has wrought! In the name of MarkJ, that is. Thanks again!

            • #606722

              Hi Al,

              I’m glad to hear that it worked!

              As for getting the file to execute automatically, I would suggest renaming it to default.asp rather than trying to do an onLoad with another file.

              (Keep in mind that the Microsoft world treats default.htm/asp as the default page rather than index.html – that’s the Unix/Netscape default.)

              One more thing… As for getting the icon images to show, be sure to download the image files from the ASP101 sample page. I had to do it manually because I never found a zipped sourcefile with all of the source and images included. After saving the images, upload them to a folder called images – created as a root-level folder.

              Let me know if you have problems with this. There is a place in the code that we can adjust to show a fixed images folder if necessary.

              HTH

            • #606726

              Default.asp it shall be. See there, that’s one mo’ thing I just learned from ya! I didn’t know about what the “default” conventions were.

              I hope I got back to my web page fast enough. I had accidently placed a graphic up there that’s in rather bad taste. I just now went back and deleted it. I guess I also need to do something about that first “Contents of” statement where it says nothing else. I didn’t realize there were icons and such involved, so I never looked for them, but I’ll go back and do what you did right after lunch. Thanks again, MY FRIEND! (Hope that’s not taking too much liberty)

            • #606780

              Hi Al,

              I completely forgot about the “Contents of ” line… I changed a variable name and forgot to change the corresponding variable in that line.

              If you don’t want to see the line at all, you can delete the line in the file that says: Contents of

              OR, if you want it to read accurately, you can change the variable “strPath” to “strFolder” (without the quotes). I changed strPath to strFolder earlier in the file and didn’t realize it was used again.

              [indent]


              …taking too much liberty…


              [/indent]Not at all! I’m always glad to help!

            • #606782

              Looks like while you were looking, I was “hacking.” (Sorry ’bout that) I use a program called Araxis Merge for file or folder comparison, so I ran the original I downloaded against your improved modification and discovered that STRPATH variable hanging out there by itself. I did as you suggested above and changed it to your STRFOLDER variable but it proved to be a little much. On my server, when you layout a full path, you get server path info that isn’t necessary to show the “public.” So, what I did was to just change it to a title and made it a tad larger. Hope you don’t mind.

              What I did have trouble with was the path to the icons. I tried putting them in a path called IMAGES at two different levels on my site and couldn’t get ’em to show up. Finally, in desperation I removed the period ( ./images ) in that line of code and it worked. What’s the period supposed to signify? Is it like the old DOS .. command to go back one directory?

              Anyway, it’s all working (I hope!) if you want to go take a peek at my visitors page. I’m greatly indebted to you, Mark for hangin’ with me…..

            • #606787

              Hey Al – One more thing I forgot to mention earlier.

              Regarding the images folder. You may want to change the “./images” to “../images” (add a second period). You are correct – the reference is a holdover from the DOS days. Adding a second period will refer to the root folder rather than a folder on the same level (aka: /images instead of /visitors/images).

              The page looks great! I plan to use that same snippet for a page on my family’s website – thanks for all of the hard work to find it! thankyou

            • #606789

              Al, if it’s not too much trouble could you ZIP the ASP and image files so they can be downloaded by other interested loungers?

              Thanks in advance bow

            • #606831

              OK fellow Lounge’ers, there is a Zip file on my web site with the ASP script that MarkJ helped me fix up. If you’ve been reading this thread, you know what it’s all about. If you’re interested in downloading the script, go to my Visitor Page on my web site. You’ll see what the script does by listing the files on that page and you can download LISTFILES.ZIP if you need this same kind of thing on your web site.

              Thanks to MarkJ for all his help! thankyou

            • #607104

              By the way, Mark, I’m sure you know this but the DEFAULT.ASP script works in any directory you place it. I put a copy of it for test in another directory on my web site that has a gazillion photos in it and, shazam, works like a charm. The only thing it doesn’t do is sub-directories below, unless you also put a copy of the script in each directory. And that’s cool – it’s a small file….. My point being, your mod to “automate” the folder name is a lifesaver!

            • #607107

              Isn’t it great! Yeah, the only catch is putting a copy of the Default.asp file in each folder.

              I have another treat for you… I took a few minutes to monkey around with the Folder Name issue. By adding one line and changing another variable name, you can now have the folder’s Relative path display. I also added a link that will take you to the parent folder.

              I also created an icon for ZIP files, since that is a very popular format for public download folders.

              I’m sure there are more elegant solutions out there, but this seems to work pretty well.

              I’ve included a zip file with the updated ASP file and all of the icons (including the new ZIP icon).

              Thanks for the opportunity to produce something kinda nice thankyou

              Enjoy!

            • #607137

              Hey, my friend, works like a charm. The “double-dot” thing (which I forgot to change) works as you said it would. The return to parent is a good, functional touch. The revised zip is up there in case you want to refer anyone. (I don’t know if you do anything like that at your web site. Guess I better take a look noevil )

            • #607138

              HI Al,

              Thanks for re-zipping the file on your site. Unfortunatley, I have been so busy doing work for clients that I haven’t had time to get the design for my own site finalized. I just bought the domain and web space a couple of months ago.

              You can view my Files page to see our project up and running: http://johnstondata.com/files%5B/url%5D

              I hope to have a little time to get my site finalized and posted in the next 2 weeks or so.

            • #607144

              [indent]


              …..Unfortunatley, I have been so busy doing work for clients…..


              [/indent] Whaddya talkin’ about, that pays the bills! All I can give ya is clapping a big round of applause and a couple attaboys….. Unless of course, you happen to drive “down south” here where I could at least buy ya a cold beer.

            • #607197

              [indent]


              …a cold beer…


              [/indent]
              That sounds like a plan! I’ll shoot you a message when I head down that way next. cheers

            • #608596

              That “put a copy in each directory” really bothered me. So I took a look at the script, and added a little code so that you can specify the “home” directory in the script, but run the script from anywhere. And since I like JavaScript on the server, I did a version using JavaScript, which is easier for string manipulation, but more work for interating through collections. To each his/her own…

            • #608636

              Hi Charlie,

              That’s pretty impressive. I agree that it’s less than efficient to place a copy of the script in each folder. Your solution is quite creative and well-crafted!

              Thanks for your hard work thankyou

    • #606421

      If they’re hosting you on IIS, it may be very simple – depending on whether or not they allow you any control over the configuration of your web and/or virtual directories. IIS allows directory browsing (which is what you’re doing when you get a list of files from a directory in FTP like fashion), but not by default. It needs to be turned on. If you can get this turned on for the directory you want to make public, you’re all set with no coding. If they won’t do that, you’ll need to use script as suggested in the previous responses.

      HTH

      • #606442

        Yeah Charlie, thanks but they (host) evidently don’t want to be “bothered.” It’s a low-price, low-SUPPORT kinda deal. It was they who told me I would need to use a Perl script to do the job. I’ve spent considerable time this afternoon searching and so far haven’t come up with anything. I’ve found a number of scripts that allow one to do file management on your domain from a browser but that’s TOO MUCH. I don’t want visitors uploading or deleting files. I’ll keep a-huntun’

        • #606455

          Typical response from a web host, but you have to try. If you can get them to allow ASP (active server pages) in your web, then it’s not hard. I prefer JavaScript to VBScript, and found it’s not hard at all to list folders and files. I co-wrote an article with a colleague about using just such a script to display a music catalog (MP3s) using just the native objects available in ASP. I’ve attached some of the code from those web pages – specifically the functions that use the File System Object to list folders and files.

          Of course, most normal people use VBScript, not JavaScript on the server side. And this is probably more complicated than what you need. But I’m sure you can find code samples for this in VB if necessary. If not, let me know and I’ll come up with one.

          HTH

    Viewing 1 reply thread
    Reply To: Perl Script For Listing Files

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: