For a support for the ASP and FSO space to have the FSO everything becomes much simpler
I'm a novice. Wrote some code for everyone to learn to study
first look to support the FSO component?
<%
' FSO Component name
Dim Fsobject
fsobject= "Scripting.FileSystemObject"
'=========================================================
' Whether to support components
'=========================================================
Function isobjinstalled (strclassstring)
on Error Resume Next
isobjinstalled = False
ERR = 0
Dim xtestobj
Set xtestobj = Server.CreateObject (strclassstring)
If 0 = Err Then isobjinstalled = True
Set xtestobj = Nothing
ERR = 0
End Function
if isobjinstalled (fsobject) then
Response.Write "√"
Else
Response.Write "X"
End If%>
-------------------------------------------------------
<%
'=========================================================
' Whether to support components
'=========================================================
Function isobjinstalled (strclassstring)
on Error Resume Next
isobjinstalled = False
ERR = 0
Dim xtestobj
Set xtestobj = Server.CreateObject (strclassstring)
If 0 = Err Then isobjinstalled = True
Set xtestobj = Nothing
ERR = 0
End Function
'=========================================================
' FSO Operation
'=========================================================
' Check if a directory exists
'=========================================================
Function Checkdir (FolderPath)
Folderpath=server.mappath (".") & "" &folderpath
Set fso= CreateObject (Fsobject)
If FSO. FolderExists (FolderPath) then
Checkdir = True
Else
Checkdir = False
End If
Set fso= Nothing
End Function
'=========================================================
' generates a directory based on the specified name
'=========================================================
Function Makenewsdir (foldername)
Dim Fs0
Set fso= CreateObject (Fsobject)
Set fs0= FSO. CreateFolder (foldername)
Set fso = Nothing
End Function
'=========================================================
' Create a new folder if the folder does not exist
'=========================================================
Function Checkfolder (FolderPath)
if Checkdir (folderpath) = False Then ' If folder does not exist
Makenewsdir (folderpath) ' Just build a folder
End If
End Function
'=========================================================
' Delete Folder
'=========================================================
Function Deletefoldera (folderpath)
Dim Path
Set fso = CreateObject (Fsobject)
Path=request. ServerVariables ("Appl_physical_path") &folderpath
FSO. DeleteFolder (PATH)
Set fso = Nothing
End Function
'=========================================================
' Change folder name
'=========================================================
Function MoveFolder (foldername,newfoldername)
Isfso
Set fso = CreateObject (Fsobject)
fso.movefolder "" &request. ServerVariables ("Appl_physical_path") & "" &foldername& "", "" &request. ServerVariables ("Appl_physical_path") & "&newfoldername&" "
Set FSO =nothing
End Function
'=========================================================
' deletes the specified file
'=========================================================
Function deletefile (file)
Set fso = CreateObject (Fsobject)
FSO. DeleteFile request. ServerVariables ("Appl_physical_path") &file
Set fso = Nothing
End Function
'=========================================================
' backs up the specified file
'=========================================================
Function CopyFile (oldfile,newfile)
Set fso = CreateObject (Fsobject)
on Error Resume Next
Set Fso=server.createobject (fsobject)
Oldfile=server.mappath (oldfile)
if err.number>0 Then call alert ("Original path Error!", "")
Newfile=server.mappath (newfile)
if err.number>0 Then call alert ("New path Error!", "")
FSO. CopyFile Oldfile,newfile ' Overwrite the original file
if err.number>0 Then call alert (Err.Description, "")
Set fso=nothing
End Function
'=========================================================
' Transfer specified file
'=========================================================
Function MoveFile (oldfile,newfile)
Set fso = CreateObject (Fsobject)
on Error Resume Next
Set fso=server.createobject (fsobject)
Oldfile=server.mappath (oldfile)
if err.number>0 Then call alert ("Original path Error!", "")
Newfile=server.mappath (newfile)
If err.number>0 Then call alert ("New path Error!", "")
' FSO. MoveFile Oldfile,newfile ' cannot overwrite the original file
FSO. MoveFile "D:odatatest.txt", "D:odatabackuptest3.txt"
if err.number>0 Then call alert (Err.Description, "")
Set fso=nothing
End Function
'=========================================================
' Read file code
'=========================================================
Function loadfile (file) reads files
Dim ftemp
Set fso = CreateObject (Fsobject)
Set Ftemp=fso. OpenTextFile (Server.MapPath ("&file&"), 1)
loadfile=ftemp. ReadAll
ftemp. Close
Fso.close
Set fso=nothing
End Function
'=========================================================
' Generate files from code
'=========================================================
'========================================
' file generates filename
Code
for
' code files
'========================================
Function savefile (file,code) ' Save file
Dim MyFile
Set fso = CreateObject (Fsobject)
Set MyFile = fso. CreateTextFile (Server.MapPath (file), True)
MyFile.WriteLine (code)
Myfile.close
Set myfile=nothing
End Function
'=========================================================
' Compressed Database
'=========================================================
'========================================
' dbpath data file path
' boolIs97 access97 compression
'========================================
Function compactdb (dbpath,boolis97)
Dim Strdbpath,fso,engine
Dbpath=server.mappath (DBPath)
Strdbpath = Left (Dbpath,instrrev (DBPath, ""))
Set fso = CreateObject (Fsobject)
If FSO. FileExists (dbpath) Then
Set Engine = CreateObject ("JRO. JetEngine ")
If boolIs97 = "True" Then
Dim jet_3x
engine.compactdatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & DBPath, _
"Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Strdbpath & "Temp.mdb" _
& "Jet oledb:engine type=" & jet_3x
Else
engine.compactdatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & DBPath, _
"Provider=Microsoft.Jet.OLEDB.4.0; Jet oledb:database password= "&dbpw&";D ata source= &strDBPath& "Temp.mdb"
End If
FSO. CopyFile Strdbpath & "Temp.mdb", DBPath
Fso. DeleteFile (strdbpath& "Temp.mdb")
Set fso = Nothing
Set Engine = Nothing
compactdb= "Current database, has been compressed successfully!"
Else
compactdb= "database name or path is incorrect. Please try again! "
End If
End Function
%>