FileSystem對(duì)象常用的文件設(shè)置函數(shù)
發(fā)表時(shí)間:2023-08-17 來(lái)源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]FileSystem對(duì)象常用的文件操作函數(shù)1、root函數(shù)格式 root()功能描述 返回一個(gè)路徑串變量應(yīng)用代碼 'sample string = c:\intels\jingcaichun...
FileSystem對(duì)象常用的文件操作函數(shù)1、root
函數(shù)格式 root()
功能描述 返回一個(gè)路徑串變量
應(yīng)用代碼 'sample string = c:\intels\jingcaichunfeng\'
Public Function root()
root = Request.ServerVariables("Appl_Physical_Path")
End Function 2、url
函數(shù)格式 url()
功能描述 返回一個(gè)URL串變量
應(yīng)用代碼 'sample string = http://www.intels.net/filesys.asp'
Public Function url()
url ="http://";&Request.ServerVariables("Server_Name")
&Request.ServerVariables("Script_Name")
End Function 3、mkdir
函數(shù)格式 mkdir( DIrName )
功能描述 創(chuàng)建一個(gè)目錄并返回信息
應(yīng)用代碼 Public Function mkdir( xVar )
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If Sys.FolderExists( xVar ) Then
msg ="抱歉,該目錄已存在! "
Else
Sys.CreateFolder( xVar )
msg ="恭喜,目錄創(chuàng)建成功! "
End If
Set Sys = Nothing
mkdir = msg
End Function4、rmdir
函數(shù)格式 rmdir( DirName )
功能描述 刪除一個(gè)目錄并返回信息
應(yīng)用代碼 Public Function rmdir( xVar )
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If Sys.FolderExists( xVar ) Then
Sys.DeleteFolder( xVar )
msg ="恭喜,目錄刪除成功!"
Else
msg ="抱歉,該目錄還未被創(chuàng)建! "
End If
Set Sys = Nothing
rmdir = msg
End Function5、isdir
函數(shù)格式 isdir( DirName )
功能描述 檢查一個(gè)目錄是否存在并返回信息
應(yīng)用代碼 Public Function isdir( xVar )
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If Sys.FolderExists( xVar ) Then
msg = True
Else
msg = False
End If
Set Sys = Nothing
isdir = msg
End Function6、cpdir
函數(shù)格式 cpdir( DirName, Destination, OverWrite )
功能描述 復(fù)制文件夾并返回信息
應(yīng)用代碼 Public Function cpdir( xVar, yVar, zVar )
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If Sys.FolderExists( xVar ) Then
Sys.CopyFolder xVar, root&yVar, zVar
msg ="恭喜,目錄復(fù)制成功!"
Else
msg ="抱歉,沒有找到您想要的目錄!"
End If
Set Sys = Nothing
cpdir = msg
End Function7、mvdir
函數(shù)格式 mvdir( DirName, Destination )
功能描述 移動(dòng)一個(gè)文件夾并返回信息
應(yīng)用代碼 Public Function mvdir( xVar, yVar )
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If Sys.FolderExists( xVar ) Then
Sys.MoveFolder xVar, root&yVar
msg ="恭喜,目錄夾已移動(dòng)!"
Else
msg ="抱歉,沒有找到您想要的目錄!"
End If
Set Sys = Nothing
mvdir = msg
End Function8、isfile
函數(shù)格式 isfile( FileName )
功能描述 檢查文件是否存在并返回信息
應(yīng)用代碼 Public Function isfile( xVar )
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If Sys.FileExists( xVar ) Then
msg = True
Else
msg = False
End If
Set Sys = Nothing
isfile = msg
End Function9、wfile
函數(shù)格式 wfile( FileName, OverWrite, String )
功能描述 寫入串到一個(gè)文件并返回信息
應(yīng)用代碼 Public Function wfile( xVar, yVar, zVar )
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If yVar Then
Set Txt = Sys.OpenTextFile( xVar, 2 )
Txt.Write( zVar )
Txt.Close
msg ="恭喜,文件創(chuàng)建成功并保存!"
Else
If Sys.FileExists( xVar ) Then
msg ="抱歉,文件已經(jīng)存在!"
End If
Set Sys = Nothing
wfile = msg
End Function10、rfile
函數(shù)格式 rfile( FileName )
功能描述 讀取一個(gè)文件并返回信息
應(yīng)用代碼 Public Function rfile( xVar )
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If Sys.FileExists( xVar ) Then
Set Txt = Sys.OpenTextFile( xVar, 1 )
msg = Txt.ReadAll
Txt.Close
Else
msg ="抱歉,文件不存在!"
End If
Set Sys = Nothing
rfile = msg
End Function11、afile
函數(shù)格式 afile( FileName, String )
功能描述 添加串到一個(gè)文件并返回信息
應(yīng)用代碼 Public Function afile( xVar, zVar )
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If Sys.FileExists( xVar ) Then
Set Txt = Sys.OpenTextFile( xVar, 8 )
Txt.Write( zVar )
Txt.Close
msg ="恭喜,文件添加成功并保存!"
Else
msg ="抱歉,文件不存在!"
End If
Set Sys = Nothing
afile = msg
End Function12、cpfile
函數(shù)格式 cpfile( FileName, Destination, OverWrite )
功能描述 復(fù)制一個(gè)文件并返回信息
應(yīng)用代碼 Public Function cpfile( xVar, yVar, zVar )
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If Sys.FileExists( xVar ) Then
Sys.CopyFile xVar, root&yVar, zVar
msg ="恭喜,文件復(fù)制成功!"
Else
msg ="抱歉,文件復(fù)制失敗!"
End If
Set Sys = Nothing
cpfile = msg
End Function13、mvfile
函數(shù)格式 mvfile( FileName, Destination )
功能描述 移動(dòng)一個(gè)文件并返回信息
應(yīng)用代碼 Public Function mvfile( xVar, yVar )
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If Sys.FileExists( xVar ) Then
Sys.MoveFile xVar, root&yVar
msg ="恭喜,文件移動(dòng)成功!"
Else
msg ="抱歉,文件移動(dòng)失敗!"
End If
Set Sys = Nothing
mvfile = msg
End Function14、rmfile
函數(shù)格式 rmfile( FileName )
功能描述 刪除一個(gè)文件并返回信息
應(yīng)用代碼 Public Function rmfile( xVar )
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If Sys.FileExists( xVar ) Then
Sys.DeleteFile( xVar )
msg ="恭喜,文件刪除成功!"
Else
msg ="抱歉,文件刪除失敗!"
End If
Set Sys = Nothing
rmfile = msg
End Function