asp的文件函數
紅過一時間的修改,現在的這個終於可以用了
<%
'request.ServerVariables("APPL_PHYSICAL_PATH") 這個是站點路徑
'FSO组件名称
dim FSObject
FSObject="Scripting.FileSystemObject"
'=========================================================
'◆是否支持组件
'=========================================================
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 操作
'=========================================================
'◆检查某一目录是否存在
'=========================================================
Function CheckDirs(folderpath)
folderpath=server.MapPath("../company/"&folderpath)
Set fso= CreateObject(FSObject)
If fso.FolderExists(folderpath) then '如果存在就True
CheckDirs = True
Else
CheckDirs = False
End if
Set fso= nothing
End Function
'=========================================================
'◆ 根据指定名称生成目录
'=========================================================
Function MakeNewsDir(foldername)
dim fs0
Set fso= CreateObject(FSObject)
Set fs0= fso.CreateFolder(foldername)
Set fso = nothing
MakeNewsDir= foldername
End Function
'=========================================================
'◆ 如果文件夹不存在则建立新文件夹 ◆
'=========================================================
Function checkFolder(folderpath)
If CheckDirs(folderpath) = false Then '如果文件夹不存在
MakeNewsDir(folderpath) '就建一个文件夹
checkFolder=true
else
checkFolder=false
end if
end Function
'=========================================================
'◆ 删除文件夹 ◆
'=========================================================
Function DeleteFoldera(foldername)
dim path
Set fso = CreateObject(FSObject)
fso.DeleteFolder(foldername)
Set fso = nothing
end Function
'=========================================================
'◆ 如果文件夹存在则刪除 ◆
'=========================================================
Function deleteFolder(folderpath)
If CheckDirs(folderpath) = true Then '如果文件夹不存在
DeleteFoldera(folderpath) '刪除成功
deleteFolder=true
else
deleteFolder=false
end if
end Function
'=========================================================
'◆ 更改文件夹名称 ◆
'=========================================================
Function RenameFolder(foldername,newfoldername)
If CheckDirs(foldername) = false then
RenameFolder=false
Elseif CheckDirs(newfoldername)= true then
RenameFolder=false
Else
Set fso = CreateObject(FSObject)
fso.moveFolder foldername,newfoldername
RenameFolder=true
Set fso =nothing
End if
End Function
'=========================================================
'◆ 删除指定文件 ◆
'=========================================================
Function DeleteFile(file)
Set fso = CreateObject(FSObject)
fso.DeleteFile file
Set fso = nothing
End Function
'以下目錄,都在compay這個目錄下
'response.Write "<br>文件夾是否存在"&CheckDirs("aabbaa")
'response.Write "<br>文件夾是否刪除"&deleteFolder("aabbaa")
'response.Write "<br>文件夾是否存在"&CheckDirs("aabbaa")
'response.Write "<br>文件夾是否創建"&checkFolder("aabbaa")
'response.Write "<br>文件夾是否存在"&CheckDirs("aabbaa")
'response.Write "<br>文件夾是否改名"&RenameFolder("aabbaa","adfasaffad")
%>
'request.ServerVariables("APPL_PHYSICAL_PATH") 這個是站點路徑
'FSO组件名称
dim FSObject
FSObject="Scripting.FileSystemObject"
'=========================================================
'◆是否支持组件
'=========================================================
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 操作
'=========================================================
'◆检查某一目录是否存在
'=========================================================
Function CheckDirs(folderpath)
folderpath=server.MapPath("../company/"&folderpath)
Set fso= CreateObject(FSObject)
If fso.FolderExists(folderpath) then '如果存在就True
CheckDirs = True
Else
CheckDirs = False
End if
Set fso= nothing
End Function
'=========================================================
'◆ 根据指定名称生成目录
'=========================================================
Function MakeNewsDir(foldername)
dim fs0
Set fso= CreateObject(FSObject)
Set fs0= fso.CreateFolder(foldername)
Set fso = nothing
MakeNewsDir= foldername
End Function
'=========================================================
'◆ 如果文件夹不存在则建立新文件夹 ◆
'=========================================================
Function checkFolder(folderpath)
If CheckDirs(folderpath) = false Then '如果文件夹不存在
MakeNewsDir(folderpath) '就建一个文件夹
checkFolder=true
else
checkFolder=false
end if
end Function
'=========================================================
'◆ 删除文件夹 ◆
'=========================================================
Function DeleteFoldera(foldername)
dim path
Set fso = CreateObject(FSObject)
fso.DeleteFolder(foldername)
Set fso = nothing
end Function
'=========================================================
'◆ 如果文件夹存在则刪除 ◆
'=========================================================
Function deleteFolder(folderpath)
If CheckDirs(folderpath) = true Then '如果文件夹不存在
DeleteFoldera(folderpath) '刪除成功
deleteFolder=true
else
deleteFolder=false
end if
end Function
'=========================================================
'◆ 更改文件夹名称 ◆
'=========================================================
Function RenameFolder(foldername,newfoldername)
If CheckDirs(foldername) = false then
RenameFolder=false
Elseif CheckDirs(newfoldername)= true then
RenameFolder=false
Else
Set fso = CreateObject(FSObject)
fso.moveFolder foldername,newfoldername
RenameFolder=true
Set fso =nothing
End if
End Function
'=========================================================
'◆ 删除指定文件 ◆
'=========================================================
Function DeleteFile(file)
Set fso = CreateObject(FSObject)
fso.DeleteFile file
Set fso = nothing
End Function
'以下目錄,都在compay這個目錄下
'response.Write "<br>文件夾是否存在"&CheckDirs("aabbaa")
'response.Write "<br>文件夾是否刪除"&deleteFolder("aabbaa")
'response.Write "<br>文件夾是否存在"&CheckDirs("aabbaa")
'response.Write "<br>文件夾是否創建"&checkFolder("aabbaa")
'response.Write "<br>文件夾是否存在"&CheckDirs("aabbaa")
'response.Write "<br>文件夾是否改名"&RenameFolder("aabbaa","adfasaffad")
%>
中国青年杂志 寫了些什麼?
最近要做的事
