Download Windows Scripting - E-Commerce - Lecture Slides and more Slides Fundamentals of E-Commerce in PDF only on Docsity! Building & Managing Web Sites FileSystemObject Object Docsity.com Windows Scripting • Microsoft Windows Script Host (WSH) allows running of VBScript and JScript natively within the base Operating System. • Introduced with Win98+, but available for Windows 95, 98, NT 4, and Win2000 operating systems. • Using scripting languages, can write script to automate common tasks, and to create powerful macros and logon scripts. Docsity.com ASP and FileSystemObject (FSO) • ASP uses native objects (Response), installable components (Browser Capabilities), & WSH objects (e.g., FileSystemObject) • The FileSystemObject (FSO) is the “window” to server’s file system. Allows querying and manipulation of: – text files – folders – drives • FSO often offers many ways to do the same thing Docsity.com Using FSO in ASP • All operations start with FSO instantiation • FSO operations involve disk access and will typically be slower than other ASP operations • FSO operations performing write operations will not scale well for heavily used pages Dim fso Set fso = Server.CreateObject("Scripting.FileSystemObject") Docsity.com Using FSO in ASP • FSO has one property - FSO.Drives • Returns a Drives collection consisting of all Drive objects available on the local machine. Set fso = Server.CreateObject("Scripting.FileSystemObject") Set dc = fso.Drives For Each d in dc Response.Write d & “<BR>” Next Docsity.com GetFolder and Files • Instantiate the Folder’s file collection to view the files in the folder. • Can query each file’s properties like Name, Size, Path, etc. sDir = Server.MapPath(".") Set fso = Server.CreateObject("Scripting.FileSystemObject") Set objFldr = fso.GetFolder(sDir) Set objFileColl = objFldr.Files For Each file in objFileColl response.write file.Name & "<BR>" Next Docsity.com GetFile Property • Another way to query a specific files’ properties. Set fs = CreateObject("Scripting.FileSystemObject") Set objFile = fs.GetFile("c:\test\test.txt") Response.Write " Name:" & objFile.Name Response.write " Size:" & objfile.Size & "<BR>" Docsity.com CreateTextFile Method • Syntax: object.CreateTextFile(filename[, overwrite[, unicode]]) • Overwrite relevant only if file already exists. Default is existing files not overwritten (false) • Instantiates a TextStream Object for manipulations Set fs = Server.CreateObject("Scripting.FileSystemObject") Set objFile = fs.CreateTextFile("c:\test\testfile.txt", True) objFile.WriteLine("This is a test.") objFile.Close Docsity.com