Using FileSystemObject to list Directory's on local computer or Remote Share
Ever need to populate a dropdown box or list a set of folders on the local computer or a remote share? Here is the code for this! This is very handy for admin's or when using Index Server to Narrow your search to a specific directory. You could easily build a string out of this code and use in a dropdown or list box. Code for getting off a remote share. Few things to remember if this share is on another computer in the same domain. The anonymous account used by your IIS web needs to be an domain user account and have rights to that share. <% @language="vbscript" %> <% folderspec = ("\\Computername\SshareName$")
Dim fs, f, f1, s, sf Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.GetFolder(folderspec) Set sf = f.SubFolders For Each f1 In sf s = s & f1.name s = s & vbCrLf Next Response.Write s %> Code for getting off the local computer You don't have to change the anonymous account used on the IIS web if the folders are listed on this computer. <% @language="vbscript" %> <% folderspec = ("c:\DirectoryName\")
Dim fs, f, f1, s, sf Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.GetFolder(folderspec) Set sf = f.SubFolders For Each f1 In sf s = s & f1.name s = s & vbCrLf Next Response.Write s %> |