Chapter 55: ASP Folder Object
ASP Folder Object.
This is not a separate W3Schools lesson (they mention it very briefly inside the “ASP FileSystemObject” and “ASP Folders” sections), but it is one of the most practical sub-objects you get when working with FileSystemObject (FSO) in real Classic ASP code — especially when you need to work with folders/directories: list files inside, create/delete folders, get folder size, count files/subfolders, check creation/modification dates, etc.
I will explain it like your favorite teacher who actually used Folder objects in production Classic ASP sites (admin file browsers, log cleanup scripts, upload folder management, report generation) — slowly, clearly, with real working examples, good habits, common mistakes, security warnings (very important!), and the exact patterns you would see in legacy Indian business/intranet/ERP/government code that still runs this way in 2026.
1. What is the Folder Object?
The Folder object is not created directly with Server.CreateObject.
You get a Folder object in one of two ways:
- From FileSystemObject.GetFolder(path) — most common
- From Drive.RootFolder, Folder.SubFolders, or Folder.ParentFolder (when navigating)
It represents one single folder/directory on disk and gives you read-only information about it (plus methods to create/delete subfolders and files inside it).
Main things you can do with a Folder object:
- Get name, path, size (recursive), date created/modified/accessed
- List all files (folder.Files) and subfolders (folder.SubFolders)
- Check if folder is root, has children, etc.
- Create/delete subfolders (CreateFolder, Delete)
- Move/copy folder (MoveFolder, CopyFolder — on FSO, not on Folder itself)
Important: Like Drive and File objects, Folder is mostly read-only for metadata. Write operations (create/delete/copy/move) are done via the parent FileSystemObject.
2. How to Get a Folder Object
Way 1 – Most common: fso.GetFolder(path)
|
0 1 2 3 4 5 6 |
Dim fso, folder, path Set fso = Server.CreateObject("Scripting.FileSystemObject") path = Server.MapPath("uploads/reports/2026") If fso.FolderExists(path) Then Set folder = fso.GetFolder(path) Response.Write "<p>Folder: " & Server.HTMLEncode(folder.Name) & "</p>" Response.Write "<p>Path: " & Server.HTMLEncode(folder.Path) & "</p>" Response.Write "<p>Created: " & folder.DateCreated & "</p>" Response.Write "<p>Files inside: " & folder.Files.Count & "</p>" Response.Write "<p>Subfolders: " & folder.SubFolders.Count & "</p>" Else Response.Write "<p>Folder not found.</p>" End If Set folder = Nothing Set fso = Nothing |
Way 2 – Loop over subfolders (very common in admin tools)
|
0 1 2 3 4 5 6 |
Dim fso, rootFolder, subFolder Set fso = Server.CreateObject("Scripting.FileSystemObject") Set rootFolder = fso.GetFolder(Server.MapPath("uploads")) Response.Write "<h3>Subfolders in /uploads/</h3>" Response.Write "<ul>" For Each subFolder In rootFolder.SubFolders Response.Write "<li>" & Server.HTMLEncode(subFolder.Name) & _ " (" & Round(subFolder.Size / 1024 / 1024, 2) & " MB)</li>" Next Response.Write "</ul>" Set subFolder = Nothing Set rootFolder = Nothing Set fso = Nothing |
3. All Important Properties of Folder Object
| Property | What it returns | Example output (typical) | Notes / Use case |
|---|---|---|---|
| folder.Name | Folder name (last part only) | “reports” | Display name |
| folder.Path | Full physical path | “C:\inetpub\wwwroot\uploads\reports” | Logging/debug |
| folder.ShortName | 8.3 short name | “REPORT~1” | Rare now |
| folder.Size | Total size of folder + all contents (recursive!) | 245760 (bytes) | Show MB/GB |
| folder.DateCreated | Creation date/time | 2025-12-01 14:30:22 | Audit trail |
| folder.DateLastAccessed | Last time folder was accessed | 2026-02-16 17:12:45 | Usage stats |
| folder.DateLastModified | Last time folder contents changed | 2026-02-15 09:45:10 | Most useful date |
| folder.Attributes | Bit flags (read-only, hidden, system, etc.) | 16 (directory) + 32 (archive) | Check permissions |
| folder.Drive | Drive letter (as string) | “C:” | Combine with Drive object |
| folder.ParentFolder | Parent Folder object | Folder object one level up | Navigate up |
| folder.Files | Collection of File objects inside | Loop with For Each file In folder.Files | List contents |
| folder.SubFolders | Collection of Folder objects inside | Loop with For Each sub In folder.SubFolders | List subdirs |
| folder.IsRootFolder | True if this is a root drive folder (C:, D:) | True / False | Rare |
| folder.ShortPath | Short 8.3 path | “C:\inetpub\wwwr~1\uploads\REPORT~1” | Rare |
4. Real-World Example – Simple Admin Folder Browser
|
0 1 2 3 4 5 6 |
<%@ Language=VBScript %> <% Option Explicit %> <!DOCTYPE html> <html> <body> <h2>Folder Browser – /uploads/</h2> <% Dim fso, folder, subFolder, file Set fso = Server.CreateObject("Scripting.FileSystemObject") Set folder = fso.GetFolder(Server.MapPath("uploads")) Response.Write "<p><strong>Folder:</strong> " & Server.HTMLEncode(folder.Path) & "</p>" Response.Write "<p><strong>Created:</strong> " & folder.DateCreated & "</p>" Response.Write "<p><strong>Size:</strong> " & Round(folder.Size / 1024 / 1024, 2) & " MB</p>" Response.Write "<p><strong>Files:</strong> " & folder.Files.Count & " | <strong>Subfolders:</strong> " & folder.SubFolders.Count & "</p>" Response.Write "<h3>Subfolders:</h3><ul>" For Each subFolder In folder.SubFolders Response.Write "<li>" & Server.HTMLEncode(subFolder.Name) & _ " (" & Round(subFolder.Size / 1024 / 1024, 2) & " MB)</li>" Next Response.Write "</ul>" Response.Write "<h3>Files:</h3><table border='1' cellpadding='5'>" Response.Write "<tr><th>Name</th><th>Size (KB)</th><th>Modified</th></tr>" For Each file In folder.Files Response.Write "<tr>" Response.Write "<td>" & Server.HTMLEncode(file.Name) & "</td>" Response.Write "<td align='right'>" & Round(file.Size / 1024, 2) & "</td>" Response.Write "<td>" & file.DateLastModified & "</td>" Response.Write "</tr>" Next Response.Write "</table>" %> </body> </html> |
5. Security & Best Practice Warnings (Critical in 2026)
- Never allow users to supply the path to GetFolder — path traversal attacks (../../windows/system32) were extremely common
- Disable write/delete permissions on web folders — many hacks used FSO to create/delete files
- Never expose physical paths (folder.Path) to users — only show folder.Name
- Use On Error Resume Next around FSO calls + check Err.Number
- Folder object has no .Close — no need to clean up except set to Nothing
- Log access — folder browsing was often abused in old sites
- In 2026 legacy code → still used for admin tools, but very risky without strict permissions
6. Teacher Summary – ASP Folder Object in Classic ASP
ASP Folder Object is:
- A read/write metadata object you get from fso.GetFolder(path) or parentFolder.SubFolders
- Represents one folder/directory on disk
- Main properties: Name, Path, Size (recursive!), DateCreated/Modified/Accessed, Files, SubFolders, Attributes, Drive
- Used for: folder listings, admin browsers, size/date display, recursive size calculation, validation
- Write operations (create/delete/copy/move subfolders) done via parent fso methods
- Always check fso.FolderExists(path) first
- Always use Server.MapPath
- AlwaysServer.HTMLEncode when displaying names/paths
- Very useful in admin tools — almost never shown to regular users
This is how serious Classic ASP sites listed directories, calculated folder sizes, built admin file managers, and validated storage — and many legacy Indian systems still use exactly this Folder object pattern in 2026.
Next class?
- Want a full recursive folder tree example (like Windows Explorer)?
- Or how to combine Folder + File + TextStream (preview folder contents)?
- Or secure FSO/Folder usage (permissions, path validation)?
- Or move to the next W3Schools topic (ASP TextStream again or ASP Cookies)?
Just tell me — I’m here! 🚀🇮🇳 Keep learning strong, Webliance! 😊
