Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listing File Names Inside a folder

Status
Not open for further replies.

sap

Technical User
Aug 20, 2001
37
IN
Can we list name of the files inside a folder using
"FileSystemObject" when we don't know the file names inside that folder ??
 
yes, of course u can! try this ;-)

<% Dim fso ' File System Object

'create Scripting.FileSystemObject object.
'We will be using this FileSystemObject to
'iterate through the files in &quot;uploaded&quot; folder and display a list of them.

Set fso = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)

Dim folder ' &quot;Uploaded&quot; Folder
Set folder = fso.GetFolder(Server.MapPath(temp_path))
'temp_path is the folder you want to read your files

'use the reference to this folder to display a list of files it contains
If folder.Size > 0 Then

ctr = 1
For Each file In folder.Files %>
response.write file.Name & &quot;, &quot; & file.Size
Next

End If

'Folder.Size property to check if the folder is empty or not. If folder contains any
'files then Folder.Size will give us total number of bytes this folder contains. So if
'folder contains any files then we iterate through the Folder.Files collection and
'display all the file names along with their sizes.
%>
 
Rachel80 (Programmer),

when i tried this code, i substituted temp_path with the path &quot; where 'sap' is the same folder or virtual directory where i stored this & all other asp files.
It gives me following error when viewed in browser ie6.

Error Type:
Server.MapPath(), ASP 0173 (0x80004005)
An invalid character was specified in the Path parameter for the MapPath method.
/asp/aspFile.asp, line 4

i tried specifying the path in different ways but it didn't work. what is wrong with it ? ?
------ sap
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top