FileSystem對象常用的文件操作函數(shù)有哪些? 1、root 函數(shù)格式 root() 功能描述 返回一個路徑串變量 應用代碼 'sample string = c:\intels\jingcaichunfeng\' Public Function root() root = Request.ServerVariables("Appl_Physical_Path") End Function
2、url 函數(shù)格式 url() 功能描述 返回一個URL串變量 應用代碼 '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)建一個目錄并返回信息 應用代碼 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 Function
4、rmdir 函數(shù)格式 rmdir( DirName ) 功能描述 刪除一個目錄并返回信息 應用代碼 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 Function
5、isdir 函數(shù)格式 isdir( DirName ) 功能描述 檢查一個目錄是否存在并返回信息 應用代碼 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 Function
6、cpdir 函數(shù)格式 cpdir( DirName, Destination, OverWrite ) 功能描述 復制文件夾并返回信息 應用代碼 Public Function cpdir( xVar, yVar, zVar ) Set Sys = Server.CreateObject("Scripting.FileSystemObject") If Sys.FolderExists( xVar ) Then Sys.CopyFolder xVar, rootyVar, zVar msg ="恭喜,目錄復制成功!" Else msg ="抱歉,沒有找到您想要的目錄!" End If Set Sys = Nothing cpdir = msg End Function
7、mvdir 函數(shù)格式 mvdir( DirName, Destination ) 功能描述 移動一個文件夾并返回信息 應用代碼 Public Function mvdir( xVar, yVar ) Set Sys = Server.CreateObject("Scripting.FileSystemObject") If Sys.FolderExists( xVar ) Then Sys.MoveFolder xVar, rootyVar msg ="恭喜,目錄夾已移動!" Else msg ="抱歉,沒有找到您想要的目錄!" End If Set Sys = Nothing mvdir = msg End Function
8、isfile 函數(shù)格式 isfile( FileName ) 功能描述 檢查文件是否存在并返回信息 應用代碼 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 Function
9、wfile 函數(shù)格式 wfile( FileName, OverWrite, String ) 功能描述 寫入串到一個文件并返回信息 應用代碼 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 Function
10、rfile 函數(shù)格式 rfile( FileName ) 功能描述 讀取一個文件并返回信息 應用代碼 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 Function
11、afile 函數(shù)格式 afile( FileName, String ) 功能描述 添加串到一個文件并返回信息 應用代碼 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 Function
12、cpfile 函數(shù)格式 cpfile( FileName, Destination, OverWrite ) 功能描述 復制一個文件并返回信息 應用代碼 Public Function cpfile( xVar, yVar, zVar ) Set Sys = Server.CreateObject("Scripting.FileSystemObject") If Sys.FileExists( xVar ) Then Sys.CopyFile xVar, rootyVar, zVar msg ="恭喜,文件復制成功!" Else msg ="抱歉,文件復制失敗!" End If Set Sys = Nothing cpfile = msg End Function
13、mvfile 函數(shù)格式 mvfile( FileName, Destination ) 功能描述 移動一個文件并返回信息 應用代碼 Public Function mvfile( xVar, yVar ) Set Sys = Server.CreateObject("Scripting.FileSystemObject") If Sys.FileExists( xVar ) Then Sys.MoveFile xVar, rootyVar msg ="恭喜,文件移動成功!" Else msg ="抱歉,文件移動失敗!" End If Set Sys = Nothing mvfile = msg End Function
14、rmfile 函數(shù)格式 rmfile( FileName ) 功能描述 刪除一個文件并返回信息 應用代碼 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