FSO file object Introduction and Common function _fso topic

Source: Internet
Author: User
Tags object model

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.