[thelist] With ASP's FileSystem Object, tell if directory is empty.

Michael K. Ahn mike at ahnfire.com
Tue Jul 23 09:25:00 CDT 2002


I forgot... do you get "." and ".." using FSO?  You'll have to ignore
those.

Michael

-----Original Message-----
From: Chris Blessing [mailto:webguy at mail.rit.edu]
Sent: Tuesday, July 23, 2002 10:24 AM
To: thelist at lists.evolt.org
Subject: RE: [thelist] With ASP's FileSystem Object, tell if directory
is empty.

Craig-

You could check the .count property of the files collection:

<%
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fname=fs.GetFolder(server.mappath("temp\"))

if fname.files.count > 0 then
	' files exist
	' list em, or do whatever
else
	' no files in this folder
	response.write "No files found."
end if

set fname=nothing
set fs=nothing
%>

You might also want to do some error checking to make sure the path
exists... like:

<%
set fs=Server.CreateObject("Scripting.FileSystemObject")
fpath = server.mappath("tempasda\")

if fs.FileExists(fpath) then
	set fname=fs.GetFolder(fpath)

	if fname.files.count > 0 then
		' files exist
		' list em, or do whatever
	else
		' no files in this folder
		response.write "No files found."
	end if
else
	response.write "Invalid path."
end if

set fname=nothing
set fs=nothing
%>

HTH!

Chris Blessing
webguy at mail.rit.edu
http://www.330i.net

> Hi all,
>
> I've got the code below which lists all the files in a directory.
What I
> don't know how to do is if the directory is empty, to simply say no
files
> were found.  I'm puzzled (doesn't take much :) ).
>
> <%
> set fs=Server.CreateObject("Scripting.FileSystemObject")
> set fname=fs.GetFolder(server.mappath("temp\"))
> for each x in fname.files
>   response.write x.name & "<br>"
> next
> set fname=nothing
> set fs=nothing
> %>
>
> Any help gladly appreciated.
>
> Regards,
> Craig.

--
For unsubscribe and other options, including
the Tip Harvester and archive of thelist go to:
http://lists.evolt.org Workers of the Web, evolt !



More information about the thelist mailing list