Wrox Programmer Forums
|
Classic ASP Components Discussions specific to components in ASP 3.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Components section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 5th, 2004, 09:53 AM
Authorized User
 
Join Date: Sep 2004
Posts: 67
Thanks: 1
Thanked 0 Times in 0 Posts
Default FSO directory listing

G'day,
I have written some code that displays all the files in a directory so that I can then upload or delete files through a web interface. Everything works fine although it seems that I am restricted to having the ASP file in the same folder with the files that I want to manage.

I don't want this because it then lists the actual ASP script file as being a file in the directory which of course I don't want users to be able to see and delete.

I have tried playing around with the Path mappings and I get all sorts of strange error messages. Is anyone able to see what I may be doing wrong from my code below.

Basically, I want to be able to run the script from say c:\script that lists the files in say c:\images and I don't want to have to put the script file in c:\images with the image files.

================================================== =============
The code:


strPathInfo = Request.ServerVariables("SCRIPT_NAME")
strPhysicalPath = Server.MapPath(strPathInfo)

Dim objFSO, objFile, objFileItem, objFolder, objFolderContents
set objFSO = CreateObject("Scripting.FileSystemObject")

set objFile = objFSO.GetFile(strPhysicalPath)
set objFolder = objFile.ParentFolder
Set objFolderContents = objFolder.Files


 
Old November 6th, 2004, 03:34 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

If you use server.mappath, then you will get the path where the script file is present.

strPhysicalPath = "c:\images"

Dim objFSO, objFile, objFileItem, objFolder, objFolderContents
set objFSO = CreateObject("Scripting.FileSystemObject")

set objFile = objFSO.GetFile(strPhysicalPath)
set objFolder = objFile.ParentFolder
Set objFolderContents = objFolder.Files

strPhysicalPath can come from database or ssome config file.


Om Prakash
 
Old November 6th, 2004, 04:23 AM
Authorized User
 
Join Date: Sep 2004
Posts: 67
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hello, thank you for your response.

I tried your suggestion and changed the strPhysicalPath to the directory I want the script to list files for and it didn't work.

I got a "File Not Found" error when trying to use the following:

strPhysicalPath = "e:\inetpub\images\"

I then put the script inside that directory and used the following:

strPhysicalPath = "e:\inetpub\images\dirlist.asp"

which worked, but that's exactly what I want to avoid having to do. I don't want the script to be in the same directory as the files I am trying to list but it seems that the script won't run from a different directory to the one I am trying to tell it to read in the strPhysicalPath (confused)


 
Old November 6th, 2004, 05:02 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

Please check the following code:

This code can be run from any folder in any physical directory. If you are using ASP then in inetpub\wwwroot or any virtual directory.

you can enter the folder/path name for which you want to get file names.

<%
strPhysicalPath = "d:\testfolder"

'This will list all files from d:\testfolder folder.

Response.write ShowFileList("d:\python21")

Function ShowFileList(folderspec)
   Dim fso, f, f1, fc, s
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.GetFolder(folderspec)
   Set fc = f.Files
   For Each f1 in fc
      s = s & f1.name
      s = s & "<BR>"
   Next
   ShowFileList = s
End Function
%>

Om Prakash
 
Old November 7th, 2004, 03:18 AM
Authorized User
 
Join Date: Sep 2004
Posts: 67
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thank you Om Prakash

That worked perfectly!! Thanks for your help.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Listing of Directory Content ram_dwivedi Javascript 3 December 9th, 2005 05:13 AM
Ch. 10 Directory listing superkooi BOOK: Beginning ASP 3.0 1 March 3rd, 2005 07:39 AM
network directory listing using FileSystemObject? wyvern47 Classic ASP Components 1 December 15th, 2004 12:09 PM
Directory Listing Bleetz Pro JSP 1 September 20th, 2003 06:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.