教程中国
PHOTOSHOP CS9.0中文版 MAYA 8.5 FOR WINDOWS Corel Painter v9.0 Flash MX2004 中文版 Illustrator cs2 中文版
VC++6.0含sp6 中英文版 VB6.0 +sp6 简体中文版 Borland Delphi 7汉化版 MSDN for vb6.0中文版 Visual Studio 2005简体
教程中国下属 文件存储共享专家BIBIDU.COM 提供大型软件,教材,源码,电影,音乐,图书等下载 更多精品请点此进入
  您目前所在位置: 教程中国 >> 编程基地 >> ASP >> 文件实用操作函数大全 RSS订阅
文件实用操作函数大全
教程(视频,书籍)下载:  ASP.NET AutoCAD 数据库 C# ASP java photoshop 网页设计 delphi 3dmax Flash C++ VB 张孝祥 实例   更多请进入BIBIDU搜索
IT搜索引擎   
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

来源:upschool.cn
作者:
关键字:文件实用操作函数
发表日期:2006-7-26

网页显示有限 阅读全文请下载本文完整版WORD文档

上一篇:手把手教你使用VB来创建ASP组件   下一篇:浏览器中执行*.exe文件的深入探讨


2009-1-9 20:38:27
本文的相类似文章
在学习中进步 在进步中成长 教程中国相随您的成长之路
华腾联合科技股份有限公司版权所有
广告联系:Rosibo@163.com