Common File processing functions in ASP

Source: Internet
Author: User

Custom functions used to process file uploads and deletions:

<%
'''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''
'All custom vbs Functions
'''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''
Function deletefile (filename) 'deletes an object
If filename <> "" then
Set FSO = server. Createobject ("scripting. FileSystemObject ")
If FSO. fileexists (filename) then
FSO. deletefile filename
End if
Set FSO = nothing
End if
End Function
'''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''
Function createdir (byval localpath) 'creates a directory program. If there is a multi-level directory, it is created at the first level.
On Error resume next
Localpath = Replace (localpath ,"/","/")
Set fileobject = server. Createobject ("scripting. FileSystemObject ")
Patharr = Split (localpath ,"/")
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 fileobject. folderexists (cpath) Then fileobject. createfolder cpath
Next
Set fileobject = nothing
If err. Number <> 0 then
Createdir = false
Err. Clear
Else
Createdir = true
End if
End Function
 

'''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''
Function saverandfilename (byval szfilename) 'generates a new random file name based on the original file name
Randomize
'Rannum = int (90000 * RND) + 10000
'If month (now) <10 then c_month = "0" & month (now) else c_month = month (now)
'If Day (now) <10 then c_day = "0" & Day (now) else c_day = Day (now)
'If hour (now) <10 then c_hour = "0" & hour (now) else c_hour = hour (now)
'If minute (now) <10 then c_minute = "0" & minute (now) else c_minute = minute (now)
'If second (now) <10 then c_second = "0" & Second (now) else c_second = minute (now)
Fileext_a = Split (szfilename ,".")
Fileext = lcase (fileext_a (ubound (fileext_a )))

Saverandfilename = Replace (replace (now, ":", ""), "-", ""), "", "") & int (10 * RND) &". "& fileext
'Generaterandomfilename = year (now) & c_month & c_day & c_hour & c_minute & c_second & "_" & rannum & "." & fileext
End Function
'''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''
Function jaron_replacer (strcontent, start_string, end_string, replace_string)
'Cms replacement function: Source string, prefix, suffix, and character to be replaced
'Return the replaced string
Jaron_replacer = Replace (strcontent, mid (strcontent, instr (strcontent, start_string), instr (strcontent, end_string) + Len (end_string)-1), replace_string)
End Function
'''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''
Function replaceplus (strcontent, start_string, end_string, replace_string)
'In the document, all characters between start and end are deleted
On Error resume next
Markcounts = ubound (split (strcontent, start_string ))
Prestring = strcontent
For I = 0 to markcounts
Startmark = instr (1, prestring, start_string, 1)
If startmark = 0 Then exit
Compmark = instr (1, prestring, end_string, 1) + Len (end_string)
Verstring = mid (prestring, startmark, compmark-startmark)
Prestring = Replace (prestring, verstring, replace_string)
Next
Replaceplus = prestring
If err. Number <> 0 then err. Clear
End Function
'''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''
%>
A

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.