FSO means FileSystemObject, which is a file system object. The FSO object model is included in the Scripting type library (Scrrun.Dll). It also contains five objects: Drive, Folder, File, FileSystemObject and TextStream, which is very convenient for manipulating files and folders.
FSO file (File) object properties
Attribute description
DateCreated returns the date and time of creation of this folder
DateLastAccessed returns the date and time of the last access to the file
DateLastModified returns the date and time when the file was last modified
Drive returns the Drive object of the drive where the file resides
Name setting or return the name of the file
ParentFolder returns the Folder object of the parent folder of the file
Path returns the absolute path to the file, and can use a long file name
ShortName returns the file name in DOS style form 8.3
ShortPath returns the file absolute path in DOS style 8.3 form
Size returns the size (bytes) of the file
Type, if possible, returns a description string for file type
FSO file (File) object method
Use of FSO file object method
Copy one or more files to a new path
CreateTextFile creates a file and returns a TextStream object
DeleteFile deletes a file
OpenTextFile opens the file and returns the TextStream object for reading or appending
Rename the file:
The code copy is as follows: FunctionreName(sourceName, destName)
dimoFso,oFile
setoFso=server.createobject("Scripting.FileSystemObject")
setoFile=oFso.getFile(Server.mappath(sourceName))
oFile.Name=destName
SetoFso=Nothing
SetoFile=Nothing
EndFunction
Delete files
The code copy is as follows: FunctionFSOdel(fileName)
dimfso,f
setfso=server.CreateObject("scripting.filesystemobject")
f=server.MapPath(fileName)
iffso.FileExists(f)then
fso.DeleteFilef,true
endif
setf=nothing
setfso=nothing
EndFunction
Replace strings in file
The code copy is as follows: FunctionFSOreplace(fileName,Target,repString)
DimobjFSO, objCountFile, FiletempData
SetobjFSO=Server.CreateObject("Scripting.FileSystemObject")
SetobjCountFile=objFSO.OpenTextFile(Server.MapPath(fileName),1,True)
FiletempData=objCountFile.ReadAll
objCountFile.Close
FiletempData=Replace(FiletempData,Target,repString)
SetobjCountFile=objFSO.CreateTextFile(Server.MapPath(fileName),True)
objCountFile.WriteFiletempData
objCountFile.Close