This is the last post of the Scripting.FileSystemObject series. After seeing how to manipulate files and folders, how to upload files and how to get file information, I would like to show how to retrieve a folder's content. This is probably the most easy thing to do, and as usual we start by setting the variables and the object:
Change yourfolder with something like "/doc/". Then we get the content:
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
folderpath = Server.MapPath(yourfolder)
We can show the content with:
Set fileinfo = FSO.GetFolder(folderpath)
All the files in the folder are now displayed in a table. You can add different information on the file, for example the size: just add a new <td> and use the size method. Change the <tr><td>... line with:
<table width="100%" border="1">
<%For each filefound in fileinfo.Files
And so on...
If you want to make the file name clickable, replace the above line with:
As a side note on file size, you could add a little if... then.. else clause to make the size more readable:
Afterwards replace <%=filefound.Size%> in your table with <%=VarSize%>.
if Clng(filefound.Size) < 1024 then
VarSize = filefound.Size & " bytes"
VarSize = Clng(filefound.Size / 1024) & " KB"
As you can see you can play around with all the information and manipulate them according to your needs.
ASP: Scripting.FileSystemObject... how to read file or folder information
JQuery: 5 useful file upload plugins
ASP: Scripting.FileSystemObject... how to move, copy and delete a file or a folder