ASP的FSO常用操作函数。全部使用相对路径!
Const ObjFSO = "Scripting.FileSystemObject"
Rem 建立目录
Function LjfCreateFolder(Foldername)
Dim fso
If Foldername <> "" Then
Foldername = Server.MapPath(Foldername)
Set fso = Server.CreateObject(ObjFSO)
If fso.FolderExists(Foldername) = False Then
fso.CreateFolder Foldername
LjfCreateFolder = "Ok"
Else
LjfCreateFolder = "FolderExists"
End If
Set fso = Nothing
End If
End Function
Rem 删除目录
Function LjfDeleteFolder(Foldername)
Dim fso
If Foldername <> "" Then
Foldername = Server.MapPath(Foldername)
Set fso = Server.CreateObject(ObjFSO)
If fso.FolderExists(Foldername) Then
fso.DeleteFolder Foldername
LjfDeleteFolder = "Ok"
Else
LjfDeleteFolder = "NoFolder"
End If
Set fso = Nothing
End If
End Function
Rem 移动目录,参数:DirName; 预拷贝文件的相对路径,DirNewName 拷贝目标名
Function LjfMoveFolder(FolderName,FolderNewName)
Dim fso,f
If FolderName <> "" And FolderNewName <> "" Then
FolderName = Server.MapPath(FolderName)
FolderNewName = Server.MapPath(FolderNewName)
Set fso = Server.CreateObject(ObjFSO)
fso.MoveFolder FolderName,FolderNewName
Set fso = Nothing
LjfMoveFolder = "Ok"
End If
End Function
Rem 建立文件
Function LjfCreateFile(Filename)
Dim fso
If Filename <> "" Then
Filename = Server.MapPath(Filename)
Set fso = Server.CreateObject(ObjFSO)
If fso.FileExists(Filename) = False Then
fso.CreateTextFile Filename
LjfCreateFile = "Ok"
Else
LjfCreateFile = "FileExists"
End If
Set fso = Nothing
End If
End Function
Rem 删除文件
Function LjfDeleteFile(Filename)
Dim fso
If Filename <> "" Then
Filename = Server.MapPath(Filename)
Set fso = Server.CreateObject(ObjFSO)
If fso.FileExists(Filename) Then
fso.DeleteFile Filename
LjfDeleteFile = "Ok"
Else
LjfDeleteFile = "NoFile"
End If
Set fso = Nothing
End If
End Function
Rem 移动文件,参数:Filename 预拷贝文件的相对路径,Filenewname 拷贝目标名
Function LjfMoveFile(FileName,FileNewName)
Dim fso,f
If Filename <> "" And FileNewName <> "" Then
FileName = Server.MapPath(FileName)
FileNewName = Server.MapPath(FileNewName)
Set fso = Server.CreateObject(ObjFSO)
fso.MoveFile FileName,FileNewName
Set fso = Nothing
LjfMoveFile = "Ok"
End If
End Function