Common ASP file and folder operation function

Source: Internet
Author: User
Tags readfile

Below is a collection of common ASP tutorials in the development of the file and folder operation functions, there are file creation, deletion and folder deletion, create and other functions.

<%
' File action function: Write file
Private Sub WriteFile (Filename,text)
Dim fso,file
Set fso = CreateObject ("Scripting.FileSystemObject")
Set file = Fso.createtextfile (filename, true)
File.write (text)
File.close
Set file = Nothing
Set fso = Nothing
End Sub

' File action function: Read file
function ReadFile (filename)
Dim fso,file
Set fso = CreateObject ("Scripting.FileSystemObject")
Set file = Fso.opentextfile (filename, 1)
ReadFile = File.readall ()
File.close
Set file = Nothing
Set fso = Nothing
End Function

' Test whether the folder exists
function Checkfolder (folder)
Dim fso,exists
Set fso = CreateObject ("Scripting.FileSystemObject")
Checkfolder = fso.folderexists (folder)
Set fso = Nothing
End Function

' Create a folder
Private Sub CreateFolder (folder)
Dim fso
Set fso = CreateObject ("Scripting.FileSystemObject")
Fso.createfolder (folder)
Set fso = Nothing
End Sub

' Delete folder
Private Sub DeleteFolder (folder)
Dim fso
Set fso = CreateObject ("Scripting.FileSystemObject")
Fso.deletefolder (Server.MapPath (folder))
Set fso = Nothing
End Sub

' Delete file
Private Sub DeleteFile (fname)
Set fso = CreateObject ("Scripting.FileSystemObject")
If Fso.fileexists (Server.MapPath (fname)) Then
Set F = Fso.getfile (Server.MapPath (fname))
F.delete ()
Set F = Nothing
End If
Set fso = Nothing
End Sub

' Test whether the folder exists, does not exist is established
Private Sub Checksavepath (Filesavepath)
P_tmp = Split (Filesavepath, "/")
Path = ""
For i = 0 To UBound (p_tmp)
If p_tmp (i) = "" Then
Path = path & "/"
Else
Path = path & P_tmp (i) & "/"
If not Checkfolder (Server.MapPath (path)) then call CreateFolder (Server.MapPath (path))
End If
Next
End Sub
%>

Related Article

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.