分享
 
 
 

文件实用操作函数大全

王朝other·作者佚名  2006-12-16
窄屏简体版  字體: |||超大  

File System Function Library

Working with files & the FileSystem object is actually fairly easy. James Lind?n presents a full

featured function library to make it even easier.

Click Here to download the function library include file.

The purpose of this script is to make working with the file system easier. It includes functions

for manipulating directories and files. Whether you want to use this script for a web based file

manager, or simply want to make working with text files easier, the script has functions which

will streamline your code.

To use these functions, save the file above (or copy the code here to an include file), upload

the include file to your server, and include it in your scripts like this:

<!--#include file="filesys.txt"-->

For more information on include files Click Here.

For more information on the FileSystem object Click Here.

<%

' Project: InteliGenie

' Creator: James Lind?n

' Date: 1/31/01 5:14PM

'********************************************************************

' root Returns the application root root()

' url Returns the true url url()

' mkdir Creates directory on server mkdir( DIrName )

' rmdir Delete directory rmdir( DirName )

' isdir Returns boolean on folder existance isdir( DirName )

' cpdir Copy directory cpdir( DirName, Destination, OverWrite )

' mvdir Move directory mvdir( DirName, Destination )

' isfile Returns boolean on file existance isfile( FileName )

' wfile Creates file and writes string to file wfile( FileName, OverWrite, String )

' rfile Read file to string rfile( FileName )

' afile Append string to file afile( FileName, String )

' cpfile Copy file cpfile( FileName, Destination, OverWrite )

' mvfile Move file mvfile( FileName, Destination )

' rmfile Delete file rmfile( FileName )

'********************************************************************

'The root() function will return a string variable of the drive path

'sample string = c:\inetpub\wwwroot

Public Function root()

root = Request.ServerVariables( "Appl_Physical_Path" )

End Function

'********************************************************************

'The url() function will return a string variable of the web url

'sample string =

http://www.domain.com/filesys.asp

Public Function url()

url = "http://" & Request.ServerVariables( "Server_Name" )

& Request.ServerVariables( "Script_Name" )

End Function

'********************************************************************

'The mkdir() function creates a directory and returns a string variable with a pass/fail message

Public Function mkdir( xVar )

Set Sys = Server.CreateObject( "Scripting.FileSystemObject" )

If Sys.FolderExists( xVar ) Then

msg = "FAIL: Directory already exists."

Else

Sys.CreateFolder( xVar )

msg = "PASS: Directory created."

End If

Set Sys = Nothing

mkdir = msg

End Function

'********************************************************************

'The rmdir() function removes a directory and returns a string variable with a pass/fail message

Public Function rmdir( xVar )

Set Sys = Server.CreateObject( "Scripting.FileSystemObject" )

If Sys.FolderExists( xVar ) Then

Sys.DeleteFolder( xVar )

msg = "PASS: Directory removed."

Else

msg = "FAIL: Directory does not exist."

End If

Set Sys = Nothing

rmdir = msg

End Function

'********************************************************************

'The isdir() function checks to see if a directory exists and returns a boolean variable

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

'********************************************************************

'The cpdir() function copies a folder and returns a string variable with a pass/fail message

Public Function cpdir( xVar, yVar, zVar )

Set Sys = Server.CreateObject( "Scripting.FileSystemObject" )

If Sys.FolderExists( xVar ) Then

Sys.CopyFolder xVar, root & yVar, zVar

msg = "PASS: Directory copied."

Else

msg = "FAIL: Directory not found."

End If

Set Sys = Nothing

cpdir = msg

End Function

'********************************************************************

'The mvdir() function moves a folder and returns a string variable with a pass/fail message

Public Function mvdir( xVar, yVar )

Set Sys = Server.CreateObject( "Scripting.FileSystemObject" )

If Sys.FolderExists( xVar ) Then

Sys.MoveFolder xVar, root & yVar

msg = "PASS: Directory moved."

Else

msg = "FAIL: Directory not found."

End If

Set Sys = Nothing

mvdir = msg

End Function

'********************************************************************

'The isfile() function checks to see if a file exists and return a boolean variable

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

'********************************************************************

'The wfile() write a string to a file and returns a stirng variable with a pass/fail message

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 = "PASS: File created, data saved."

Else

If Sys.FileExists( xVar ) Then

msg = "FAIL: File already exists."

Else

Set Txt = Sys.OpenTextFile( xVar, 2 )

Txt.Write( zVar )

Txt.Close

msg = "PASS: File created, data saved."

End If

End If

Set Sys = Nothing

wfile = msg

End Function

'********************************************************************

'The rfile() function reads a file and returns a string variable with the contents of the file

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 = "FAIL: File does not exist."

End If

Set Sys = Nothing

rfile = msg

End Function

'********************************************************************

'The afile() function appends a string to a file and returns a string variable with a pass/fail

message

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 = "PASS: File appended, data saved."

Else

msg = "FAIL: File does not exist."

End If

Set Sys = Nothing

afile = msg

End Function

'********************************************************************

'The cpfile() function copies a files and returns a string variable with a pass/fail message

Public Function cpfile( xVar, yVar, zVar )

Set Sys = Server.CreateObject( "Scripting.FileSystemObject" )

If Sys.FileExists( xVar ) Then

Sys.CopyFile xVar, root & yVar, zVar

msg = "PASS: File copied."

Else

msg = "FAIL: File not found."

End If

Set Sys = Nothing

cpfile = msg

End Function

'********************************************************************

'The mvfile() function moves a file and returns a string variable with a pass/fail message

Public Function mvfile( xVar, yVar )

Set Sys = Server.CreateObject( "Scripting.FileSystemObject" )

If Sys.FileExists( xVar ) Then

Sys.MoveFile xVar, root & yVar

msg = "PASS: File moved."

Else

msg = "FAIL: File not found."

End If

Set Sys = Nothing

mvfile = msg

End Function

'********************************************************************

'The rmfile() function deletes a file and returns a string variable with a pass/fail message

Public Function rmfile( xVar )

Set Sys = Server.CreateObject( "Scripting.FileSystemObject" )

If Sys.FileExists( xVar ) Then

Sys.DeleteFile( xVar )

msg = "PASS: File deleted."

Else

msg = "FAIL: File not found."

End If

Set Sys = Nothing

rmfile = msg

End Function

%>

3/18/01 by James Lind?n

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有