Public Function checkandcreatefolder (Foldername)
FLDR = server. mappath (Foldername)
Set FSO = Createobject ("scripting. FileSystemObject ")
If not FSO. folderexists (FLDR) then
FSO. createfolder (FLDR)
End if
Set FSO = nothing
End Function
Check whether the folder exists. If the folder does not exist, create a folder. This function does not return a value.
Example: checkandcreatefolder ("asp ")
Check whether ASP folders exist in the current directory. If no ASP folder exists, create ASP folders.
Asp fso Functions
'// Provides a common interface for File Processing
Class FileSystemObject
'/*
'* Function Description: delete an object
'* Input parameter: Filename -- file relative path
'*/
Public Function delfile (filename)
Dim getpath
Getpath = "/"
Set FSO = server. Createobject ("scripting. FileSystemObject ")
Getpath = Replace (getpath & filename ,"//","/")
If FSO. fileexists (server. mappath (getpath) = true then
FSO. deletefile server. mappath (getpath)
End if
Set FSO = nothing
End Function
'/*
'* Function Description: determines whether a path exists. A path is created if it does not exist.
'* Input parameter: SaveFilePath -- relative path, for example,/uploadfiles/newsfiles
'*/
Public Function createpath (SaveFilePath)
Dim declarepath, fileobj, filepath
Declarepath = "/"
Set fileobj = server. Createobject ("scripting. FileSystemObject ")
For each filepath in Split (SaveFilePath ,"/")
Declarepath = Replace (declarepath & filepath &"/","//","/")
If fileobj. folderexists (server. mappath (declarepath) = false then
Fileobj. createfolder (server. mappath (declarepath) 'create a folder
End if
Next
Set fileobj = nothing
Createpath = declarepath
End Function
'/*
'* Function Description: rename a folder
'* Input parameter: getpath -- folder path
'* Input parameter: oldname -- Name of the old folder
'* Input parameter: newname -- New Folder name
'*/
Public Function renfolder (getpath, oldname, newname)
Dim FSO
If oldname = "" Or newname = "" then
Exit Function
Else
If oldname = newname then exit function
End if
Set FSO = server. Createobject ("scripting. FileSystemObject ")
If FSO. folderexists (server. mappath (getpath & newname) then
Response. Write "<script language = JavaScript> alert ('Directory already exists !! '); This. History. Go (-1); </SCRIPT>"
Response. End ()
End if
'// If the old Folder does not exist, create
If not FSO. folderexists (server. mappath (getpath & oldname) then
Createpath (getpath & oldname)
End if
FSO. movefolder server. mappath (getpath & oldname), server. mappath (getpath & newname)
Set FSO = nothing
'Response. redirect request. servervariables ("http_referer ")
End Function
'/*
'* Function Description: Save the current file
'* Input parameter: getpath -- file path
'* Input parameter: getcontent -- saved content
'* Input parameter: GetFile -- saved file name
'*/
Public Function saveeditfile (getpath, getcontent, GetFile)
If getcontent = "" Or GetFile = "" Then exit function
Set FSO = server. Createobject ("scripting. FileSystemObject ")
Set cf = FSO. createtextfile (server. mappath (getpath & GetFile), true)
Cf. Write getcontent
Cf. Close
Set cf = nothing
Set FSO = nothing
'Response. redirect request. servervariables ("http_referer ")
End Function
End Class