FSO means FileSystemObject, which is the file system object. The FSO object model is contained in the Scripting type library (SCRRUN.DLL), which includes drive, folder, file, FileSystemObject, and TextStream five objects that are handy for manipulating files and folders.
FSO file (file) object properties
Attribute description
DateCreated returns the date and time the folder was created
Datelastaccessed returns the date and time the file was last accessed
DateLastModified returns the date and time the file was last modified
Drive returns the Drive object of the drive where the file resides
Name Sets or returns the names of the files
ParentFolder returns the Folder object for the parent of the file
Path returns the absolute path to the file, using long file names
ShortName Returns a DOS-style 8.3-form filename
ShortPath returns a DOS-style 8.3-form file absolute path
Size returns the file in bytes
Type returns a description string for a file type, if possible
FSO file (file) object method
FSO File Object Method purpose
CopyFile copy one or more files to a new path
CreateTextFile creates a file and returns a TextStream object
DeleteFile Delete a file
OpenTextFile opens the file and returns the TextStream object to read or append
To rename a file:
Copy Code code as follows:
Function ReName (Sourcename,destname)
Dim ofso,ofile
Set Ofso=server.createobject ("Scripting.FileSystemObject")
Set Ofile=ofso.getfile (Server.MapPath (sourceName))
Ofile.name=destname
Set ofso=nothing
Set ofile=nothing
End Function
deleting files
Copy Code code as follows:
Function Fsodel (FileName)
Dim fso,f
Set fso = server. CreateObject ("Scripting.FileSystemObject")
F=server. MapPath (FileName)
If FSO. FileExists (f) Then
Fso. DeleteFile F,true
End If
Set F = Nothing
Set fso = Nothing
End Function
Replace a string in a file
Copy Code code as follows:
Function Fsoreplace (filename,target,repstring)
Dim Objfso,objcountfile,filetempdata
Set objFSO = Server.CreateObject ("Scripting.FileSystemObject")
Set objcountfile = objFSO.OpenTextFile (Server.MapPath (fileName), 1,true)
Filetempdata = Objcountfile.readall
Objcountfile.close
Filetempdata=replace (filetempdata,target,repstring)
Set Objcountfile=objfso.createtextfile (Server.MapPath (fileName), True)
Objcountfile.write Filetempdata
Objcountfile.close
Set objcountfile=nothing
Set objFSO = Nothing
End Function