Use fso in ASP to implement operation functions such as folder or file moving and renaming
Source: Internet
Author: User
ASP uses FSO to move files
Function movefiles (sfolder, dfolder)
On Error resume next
Dim FSO
Set FSO = server. Createobject ("scripting. FileSystemObject ")
If FSO. folderexists (server. mappath (sfolder) and FSO. folderexists (server. mappath (dfolder) then
FSO. copyfolder server. mappath (sfolder), server. mappath (dfolder)
Movefiles = true
Else
Movefiles = false
Set FSO = nothing
Call alertbox ("the system does not find the specified path [" & sfolder & "]! ", 2)
End if
Set FSO = nothing
End Function
ASP
Function renamefolder (sfolder, dfolder)
On Error resume next
Dim FSO
Set FSO = server. Createobject ("scripting. FileSystemObject ")
If FSO. folderexists (server. mappath (sfolder) then
FSO. movefolder server. mappath (sfolder), server. mappath (dfolder)
Renamefolder = true
Else
Renamefolder = false
Set FSO = nothing
Call alertbox ("the system does not find the specified path [" & sfolder & "]! ", 2)
End if
Set FSO = nothing
End Function
ASP check whether the folder exists
Function checkfolder (Spath)
On Error resume next
Dim FSO
Set FSO = server. Createobject ("scripting. FileSystemObject ")
If FSO. folderexists (server. mappath (Spath) then
Checkfolder = true
Else
Checkfolder = false
End if
Set FSO = nothing
End Function
ASP checks whether the file exists
Function checkfile (Spath)
On Error resume next
Dim FSO
Set FSO = server. Createobject ("scripting. FileSystemObject ")
If FSO. fileexists (server. mappath (Spath) then
Checkfile = true
Else
Checkfile = false
End if
Set FSO = nothing
End Function
ASP
Function createdir (Spath)
Dim FSO, patharr, I, path_level, pathtmp, cpath
On Error resume next
Spath = Replace (Spath ,"\","/")
Set FSO = server. Createobject ("scripting. FileSystemObject ")
Patharr = Split (Spath ,"/")
Path_level = ubound (patharr)
For I = 0 to path_level
If I = 0 then pathtmp = patharr (0) & "/" else pathtmp = pathtmp & patharr (I )&"/"
Cpath = left (pathtmp, Len (pathtmp)-1)
If not FSO. folderexists (cpath) Then FSO. createfolder (cpath)
Next
Set FSO = nothing
If err. Number <> 0 then
Err. Clear
Createdir = false
Else
Createdir = true
End if
End Function
Delete a folder. Delete the folder in the system.
Function delclassfolder (Spath)
On Error resume next
Dim FSO
Set FSO = server. Createobject ("scripting. FileSystemObject ")
If FSO. folderexists (server. mappath (Spath) then
FSO. deletefolder (server. mappath (Spath ))
End if
Set FSO = nothing
End Function
Delete news content files
Function delnewsfile (Spath, filename)
On Error resume next
Dim FSO, temparr, cpath, epath, I: I = 0
Set FSO = server. Createobject ("scripting. FileSystemObject ")
Spath = Spath & filename & site_extname
If FSO. fileexists (server. mappath (Spath) then
FSO. deletefile (server. mappath (Spath ))
While (I <>-1)
I = I + 1
Epath = Replace (Spath, filename & ".", filename & "_" & I + 1 &".")
If FSO. fileexists (server. mappath (epath) then
FSO. deletefile (server. mappath (epath ))
Else
I =-1
End if
Wend
End if
End Function
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