Click to See Complete Forum and Search --> : Basic asp - file and folder search
bddosch
10-06-2003, 08:51 AM
Hi am looking for a script that searches through folders and subfolders, files in those folders. I have found a few scripts but I would like to learn the basics regarding searching through files and folders . Could anybody help in this matter please.
Thanks
DOSCH
rdoekes
10-06-2003, 09:53 AM
Files in a folder, and sub folders from this folder
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder("c:\myFolder")
Set oSubFolder = oFolder.SubFolders
For Each fFile in oFolder.Files
Response.Write "fileName = " & fFile.Name & "<br />"
Next
For Each fFolder in oSubFolder
Response.Write "folderName = " & fFolder.Name & "<br />"
Next
Hope this helps,
-Rogier Doekes
bddosch
10-06-2003, 10:11 AM
Hi rdoekes
I understand that and how it works but, how do I search for a spicific file within my folders and display it to the user. Like a search facility searching for files inside those folder?
rdoekes
10-06-2003, 10:29 AM
You could use the Item property in the file collection:
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder("c:\myFolder")
Set oFiles = oFolder.Files
Response.Write oFiles.Item("test.jpg")
this works as long as test.jpg is in the files collection. If it's not, a file not found error is returned, which error you need to trap.
Hope this helps better,
-Rogier Doekes
rdoekes
10-06-2003, 10:35 AM
Actually this is more straightforward version, if you know the whole path to a file
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
If oFSO.FileExists("c:\myFolder\myFile.ext") Then
Response.Write "file exists"
Else
Response.Write "file not found"
End if