Saturday, August 21, 2010

How can I use the FileSystemObject or the Drive object in ASP to list all files in a directory I specify?

for example you can check if a file exist by





%26lt;%


Set fs=Server.CreateObject(';Scripting.FileSy鈥?br>




If (fs.FileExists(';\\panter\test1.jpg';))=tr鈥?Then


Response.Write(';File 1.jpg exist';)


Else


Response.Write(';Call IS department';)


End If





set fs=nothing


%%26gt;





But how could I list all files in that particular \\panther\*.*.How can I use the FileSystemObject or the Drive object in ASP to list all files in a directory I specify?
You can use the Files collection:





Dim MyFolder





MyFolder = ';\\panther\\';





Dim objFSO, objFile, objFileItem, objFolder, objFolderContents





Set objFSO = CreateObject( ';Scripting.FileSystemObject'; )





Set objFile = objFSP.GetFile(MyPath)





Set objfolder = objFile.ParentFolder





Set objFolderContents = objFolder.Files





And then you can iterated through your collection:





For Each objFileItem in objFolderContents





Response.Write objFileItem.Name %26amp; ';%26lt;br%26gt;';


Response.Write objFileItem.Size %26amp; ';%26lt;br%26gt;';


Next
  • horses for loan
  • skin care
  • No comments:

    Post a Comment