Drives <% Option Explicit Dim objFileSys Dim objDrives Set objFileSys = Server.CreateObject("Scripting.FileSystemObject") Set objDrives = objFileSys.Drives %> BuildPath <% Option Explicit Dim objFileSys Dim ThePath1 Dim ThePath2 set objFileSys = Server.CreateObject("Scripting.FileSystemObject") ThePath1 = "c:\Program Files" ThePath2 = "c:\Program Files\" Response.Write objFileSys.BuildPath(ThePath1, "Office") & "
" Response.Write objFileSys.BuildPath(ThePath1, "\Office") & "
" Response.Write objFileSys.BuildPath(ThePath2, "Office") & "
" Response.Write objFileSys.BuildPath(ThePath2, "\Office") & "
" %> CreateFolder <% Option Explicit Dim objFileSys Dim TheNewFolder set objFileSys = Server.CreateObject("Scripting.FileSystemObject") set TheNewFolder = objFileSys.CreateFolder("c:\inetpub\wwwroot\myfolder") %> Delete <% Option Explicit Dim objFileSys set objFileSys = Server.CreateObject("Scripting.FileSystemObject") objFileSys.DeleteFile "c:\docs\mydoc.txt" objFileSys.DeleteFile "c:\docs\*.txt" %> Drives <% Option Explicit Dim objFileSys set objFileSys = Server.CreateObject("Scripting.FileSystemObject") Response.Write "Drive C is valid: " & objFileSys.DriveExists("C") & "
" Response.Write "Drive A is valid: " & objFileSys.DriveExists("A") & "
" Response.Write "Drive R is valid: " & objFileSys.DriveExists("R") & "
" %> FileExists <% Option Explicit Dim objFileSys set objFileSys = Server.CreateObject("Scripting.FileSystemObject") Response.Write objFileSys.FileExists("myfile.txt") & "
" Response.Write objFileSys.FileExists("..\myfile.txt") & "
" Response.Write objFileSys.FileExists("c:\docs\myfile.txt") & "
" %> FolderExists <% Option Explicit Dim objFileSys set objFileSys = Server.CreateObject("Scripting.FileSystemObject") Response.Write objFileSys.FolderExists(".\Docs\MyFolder") & "
" Response.Write objFileSys.FolderExists("MyFolder") & "
" Response.Write objFileSys.FolderExists("..\..\MyFolder") & "
" %> Path <% Option Explicit Dim objFileSys set objFileSys = Server.CreateObject("Scripting.FileSystemObject") Response.Write objFileSys.GetAbsolutePathName("") & "
" Response.Write objFileSys.GetAbsolutePathName(".\") & "
" Response.Write objFileSys.GetAbsolutePathName("..\") & "
" Response.Write objFileSys.GetAbsolutePathName("..\..\") & "
" %> GetBaseName <% Option Explicit Dim objFileSys set objFileSys = Server.CreateObject("Scripting.FileSystemObject") Response.Write objFileSys.GetBaseName("c:\docs\myfile.txt") & "
" Response.Write objFileSys.GetBaseName("myfile.txt") & "
" Response.Write objFileSys.GetBaseName("c:\docs\myfile") & "
" %> DriveName <% Option Explicit Dim objFileSys set objFileSys = Server.CreateObject("Scripting.FileSystemObject") Response.Write "" & objFileSys.GetDriveName("c:\docs\doc1.txt") & "
" Response.Write objFileSys.GetDriveName("c:\my documents") & "
" Response.Write objFileSys.GetDriveName("a:") & "
" %> Extension <% Option Explicit Dim objFileSys set objFileSys = Server.CreateObject("Scripting.FileSystemObject") Response.Write objFileSys.GetExtensionName("c:\docs\doc1.txt") & "
" Response.Write objFileSys.GetExtensionName("doc1.txt") & "
" Response.Write objFileSys.GetExtensionName("doc1") & "
" %> FileName <% Option Explicit Dim objFileSys set objFileSys = Server.CreateObject("Scripting.FileSystemObject") Response.Write "The file name is: " & objFileSys.GetFileName("c:\docs\doc1.txt") & "
" Response.Write "The file name is: " & objFileSys.GetFileName(".\doc1.txt") & "
" Response.Write "The file name is: " & objFileSys.GetFileName("c:\docs\doc1") & "
" %> Parent Folder <% Option Explicit Dim objFileSys set objFileSys = Server.CreateObject("Scripting.FileSystemObject") Response.Write objFileSys.GetParentFolderName("c:\support\docs\doc1.txt") & "
" Response.Write objFileSys.GetParentFolderName("c:\support\docs") & "
" Response.Write objFileSys.GetParentFolderName("c:\support") & "
" %> GetSpecialFolder <% Option Explicit Dim objFileSys set objFileSys = Server.CreateObject("Scripting.FileSystemObject") Response.Write "Path to Windows: " & objFileSys.GetSpecialFolder(0) & "
" Response.Write "Path to Windows/System: " & objFileSys.GetSpecialFolder(1) & "
" Response.Write "Path to Temp Folder: " & objFileSys.GetSpecialFolder(2) & "
" %> Drives Collection <% Option Explicit Dim objFileSys Dim MyDrives Dim TheDrive set objFileSys = Server.CreateObject("Scripting.FileSystemObject") set MyDrives = objFileSys.Drives Response.Write "Total Drives: " & MyDrives.Count & "
" set TheDrive = MyDrives.Item("C") Response.Write "Drive C is: " & TheDrive.DriveLetter & "
" For Each TheDrive in MyDrives Response.Write "Drive: " & TheDrive.DriveLetter & "
" Next %> Drive Object <% Option Explicit Dim objFileSys Dim MyDrives Dim TheDrive Dim TheRootFolder set objFileSys = Server.CreateObject("Scripting.FileSystemObject") set MyDrives = objFileSys.Drives set TheDrive = MyDrives.Item("E") Response.Write "Available Space: " & FormatNumber(TheDrive.AvailableSpace, 0) & "
" Response.Write "Drive Letter: " & TheDrive.DriveLetter & "
" Response.Write "Drive Type: " & TheDrive.DriveType & "
" Response.Write "File System: " & TheDrive.FileSystem & "
" Response.Write "Free Space: " & FormatNumber(TheDrive.FreeSpace, 0) & "
" Response.Write "Is Ready: " & TheDrive.IsReady & "
" Response.Write "Path: " & TheDrive.Path & "
" set TheRootFolder = TheDrive.RootFolder Response.Write "Serial Number: " & TheDrive.SerialNumber & "
" Response.Write "Share Name: " & TheDrive.ShareName & "
" Response.Write "Total Size: " & FormatNumber(TheDrive.TotalSize, 0) & "
" Response.Write "Volume Name: " & TheDrive.VolumeName & "
" %> Folders <% Option Explicit Dim objFileSys Dim MyDrives Dim TheDrive Dim TheRootFolder Dim RootFolders Dim SubFolder set objFileSys = Server.CreateObject("Scripting.FileSystemObject") set MyDrives = objFileSys.Drives set TheDrive = MyDrives.Item("E") set TheRootFolder = TheDrive.RootFolder set RootFolders = TheRootFolder.SubFolders Response.Write "Total Folders in root: " & RootFolders.Count & "
"
set SubFolder = RootFolders.Item("Admin")
RootFolders.Add "NewFolder"
For Each SubFolder in RootFolders
Response.Write SubFolder.Name & "
"
Next
%>
Folder
<%
Option Explicit
Dim objFileSys
Dim TheFolder
Dim TheFiles
Dim TheSubFolders
set objFileSys = Server.CreateObject("Scripting.FileSystemObject")
set TheFolder = objFileSys.GetFolder("c:\my documents")
Response.Write "Attributes: " & TheFolder.Attributes & "
"
Response.Write "Date Created: " & TheFolder.DateCreated & "
"
Response.Write "Date Last Accessed: " & TheFolder.DateLastAccessed & "
"
Response.Write "Date Last Modified: " & TheFolder.DateLastModified & "
"
Response.Write "Drive: " & TheFolder.Drive & "
"
Set TheFiles = TheFolder.Files
Response.Write "Is Root Folder: " & TheFolder.IsRootFolder & "
"
Response.Write "Name: " & TheFolder.Name & "
"
Response.Write "Parent Folder: " & TheFolder.ParentFolder & "
"
Response.Write "Path: " & TheFolder.Path & "
"
Response.Write "Short Name: " & TheFolder.ShortName & "
"
Response.Write "Short Path: " & TheFolder.ShortPath & "
"
Response.Write "Size: " & TheFolder.Size & "
"
Set TheSubFolders = TheFolder.SubFolders
%>
Files
<%
Option Explicit
Dim objFileSys
Dim TheFolder
Dim TheFiles
Dim AFile
set objFileSys = Server.CreateObject("Scripting.FileSystemObject")
set TheFolder = objFileSys.GetFolder("c:\my documents")
Set TheFiles = TheFolder.Files
Response.Write "Total files in collection: " & TheFiles.Count & "
" Set AFile = TheFiles.Item("nmaha.mdb") For Each AFile in TheFiles Response.Write AFile.Name & "
"
Next
%>
File
<%
Option Explicit
Dim objFileSys
Dim TheFolder
Dim TheFiles
Dim TheFile
set objFileSys = Server.CreateObject("Scripting.FileSystemObject")
set TheFolder = objFileSys.GetFolder("c:\my documents")
Set TheFiles = TheFolder.Files
set TheFile = TheFiles.Item("nmaha.mdb")
If TheFile.Attributes and 1 Then
Response.Write "The file is read only.
"
else
Response.Write "The file is not read only.
"
End If
TheFile.Attributes = TheFile.Attributes or 1
If TheFile.Attributes and 1 Then
Response.Write "The file is read only.
"
else
Response.Write "The file is not read only.
"
End If
TheFile.Attributes = TheFile.Attributes and not 1
If TheFile.Attributes and 1 Then
Response.Write "The file is read only.
"
else
Response.Write "The file is not read only.
"
End If
Response.Write "Attributes: " & TheFile.Attributes & "
"
Response.Write "Date Created: " & TheFile.DateCreated & "
"
Response.Write "Date Last Accessed: " & TheFile.DateLastAccessed & "
"
Response.Write "Date Last Modified: " & TheFile.DateLastModified & "
"
Response.Write "Drive: " & TheFile.Drive & "
"
Response.Write "Name: " & TheFile.Name & "
"
Response.Write "Parent Folder: " & TheFile.ParentFolder & "
"
Response.Write "Path: " & TheFile.Path & "
"
Response.Write "Short Name: " & TheFile.ShortName & "
"
Response.Write "Short Path: " & TheFile.ShortPath & "
"
Response.Write "Size: " & TheFile.Size & "
"
Response.Write "Type: " & TheFile.Type & "
"
%>
TextStream
<%
Option Explicit
Dim objFileSys
Dim TheTextStream
set objFileSys = Server.CreateObject("Scripting.FileSystemObject")
set TheTextStream = objFileSys.CreateTextFile("temp.txt", True)
TheTextStream.WriteLine "This is the first line."
TheTextStream.WriteLine "This is the second line."
TheTextStream.Write "No end of line."
TheTextStream.WriteBlankLines 2
TheTextStream.WriteLine "Another line."
TheTextStream.Close
set TheTextStream = objFileSys.OpenTextFile("temp.txt", 1)
Response.Write TheTextStream.ReadAll & "
"
TheTextStream.Close
set TheTextStream = objFileSys.OpenTextFile("temp.txt", 1)
Do Until TheTextStream.AtEndOfStream
Response.Write TheTextStream.ReadLine & "
"
Loop
TheTextStream.Close
set TheTextStream = objFileSys.OpenTextFile("temp.txt", 1)
Response.Write "
" & TheTextStream.Read(6) & "
"
Response.Write "On Line: " & TheTextStream.Line & "
Column: " & TheTextStream.COlumn
TheTextStream.Skip 4
Response.Write "
" & TheTextStream.Read(3) & "
" TheTextStream.SkipLine Response.Write TheTextStream.ReadLine %> Dictionary <% Option Explicit Dim ThePages set ThePages = Server.CreateObject("Scripting.Dictionary") ThePages.Add "Home", "This is the home page of the site" ThePages.Add "Support", "Here you will find our knowledge base" ThePages.Add "Contact", "This page contains our contact information" ThePages.Add "Sale", "List of our products currently on sale" Response.Write ThePages.Item("Home") & "
" Response.Write ThePages("Contact") & "
" %>