当前位置:编程学习 > asp >>

一组FSO相关FUNCTION,常用代码(也常有人问,重复问)

答案:删除文件
<%
'|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ASPWizard Copyright ?1999-2001 >>>>>>>
'|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[       Generic File Deletion      ]>>>>>>>>>>>>>>>>
'|Author: Joaquim Jos?Prates Ferreira
'|Date Created: 13/01/2001
'|Last Update: 28/06/2001
'|Dependencies:
'|Description: This function will delete unwanted files from the server...
'| V1.1: Added a new parameter [ intShowLabel ] 0 - Do not show label / 1 - Show label
'| V1.0: This function only accepts one parameter at the moment, the path with the file,
'|  below there are examples of how to call the function.
'|e.g.
'| Call Generic_FileDeletion(File path 'REQUIRED')
'| Call Generic_FileDeletion("myfile.txt")
'| Call Generic_FileDeletion("win95/myfile.txt")
'|
'|Please remember to specify a Path, otherwise an Error will occur...

Function Generic_FileDeletion(byval strpath,byval intShowLabel)

' ERROR CHECKING!!!!...
IF strpath = "" or isnull(strpath) then
Response.Write("Sorry but a path is required when calling this function")
Response.End
End IF

' ERROR CHECKING!!!!...
IF intShowLabel = "" or isnull(intShowLabel) then
Response.Write("Sorry but the paramter <b>intShowLabel</b> is missing. PARAMETER IS REQUIRED")
Response.End
End IF

Filename = Server.MapPath(strpath)

Set fs = CreateObject("Scripting.FileSystemObject")

  If fs.FileExists(filename) Then
   fs.DeleteFile(filename)

   if intShowLabel = 1 then
    response.write "File" & " <b>(" & strpath & ")</b> " & " has Been Deleted with Success.<BR>"
   end if
  Else
   response.write "No path was found, or file does not exist to delete...<BR>"
  End If

End Function
%>





copy文件


<%
'|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ASPWizard.co.uk Copyright ?1999-2001 >>>>>>>>>>>>>>>>>
'|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[       Generic_FileCopy.asp       ]>>>>>>>>>>>>>>>>
'|Author: Joaquim Jos?Prates Ferreira
'|Last Author: Joaquim Jos?Prates Ferreira
'|Date Created: 26/04/2001
'|Last Update: 26/04/2001
'|Dependencies:
'|Description: This function will copy Files From [ A ] to [ B ]
'| V1.0: This function will copy a file from one Folder to another.
'|
'|Parameters:
'| strFileSource  - We specify the path to the file to Copy
'| strFileDestination - We sepcify the path to the new file
'| strOverWrite  - We say if we want to overwright a file
'|
'|E.G:
'| Call Generic_FileCopy("D:\Xkudos\NewsX_1997.mdb","D:\Xkudos\Xkudos\Xkudos\DB\NewsX_1997.mdb",True)
Function Generic_FileCopy(ByVal strFileSource,ByVal strFileDestination,ByVal strOverWrite)
'--------------------------------[ERROR CHECKING]--------------------------------
' ERROR CHECKING!!!!...
IF strFileSource = "" or isnull(strFileSource) Then
Response.Write("Sorry but a File Source path is required when calling this function")
Response.End
End IF
' ERROR CHECKING!!!!...
IF strFileDestination = "" or isnull(strFileDestination) Then
Response.Write("Sorry but a File Destination path is required when calling this function")
Response.End
End IF
' ERROR CHECKING!!!!...[True - False]
IF strOverWrite = "" or isnull(strOverWrite) Then
Response.Write("Sorry but a File Destination path is required when calling this function")
Response.End
End IF
'--------------------------------[/ERROR CHECKING]--------------------------------
Set fso = CreateObject("Scripting.FileSystemObject")
    
If fso.FileExists(strFileSource) Then
  fso.CopyFile strFileSource, strFileDestination, strOverWrite
Else
  Response.Write("The file does not exist...")
  Response.End
End If
    
Set fso = Nothing
End Function
%>
写文件


<%
'|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ASPWizard Copyright ?1999-2002 >>>>>>>>>>>>
'|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[       Generic_FileWriter.asp ]>>>>>>>>>>>>>>>>>
'|Author: Joaquim Jos?Prates Ferreira
'|Last Author: Joaquim Jos?Prates Ferreira
'|Date Created: 24/02/2002
'|Last Update: 24/02/2002
'|Dependencies:
'|Description: This function will write a file, you just need to pass 3
'|                parameters.  And you will create files in you folder, quick and easy
'| V1.0:
'|
'|Parameters:
'| strFileName         - Required Parameter
'| strFileExtension - Required Parameter
'| strFileContent     - Required Parameter
'|
'| Example of Call:
'|        CAll Generic_FileWriter("MyFileName","HTML","The content goes here...")


Function Generic_FileWriter(strFileName,strFileExtension,strFileContent)

Set oFS = CreateObject("Scripting.fileSystemObject")
Set oTXS = oFS.OpenTextFile(Server.MapPath(strFileName & "." & strFileExtension),8,True)

oTXS.WriteLine(strFileContent)
oTXS.Close

End Function
%>

更棒的


<%
'|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ASPWizard Copyright ?1999-2001 >>>>>>>>>
'|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[       Generic_FileFerrete.asp          ]>>>>>>>>>>>
'|Author: Joaquim Ferreira
'|Date Created: 19/02/2001
'|Last Update: 20/02/2001
'|Last Author: Joaquim Ferreira
'|Dependencies: A Folder to Search On
'|Description: The following function will go to a specific folder specified by the parameter (strDirectory)
'|    And display the contents of that folder  with a URL to it.
'|  V1.1: Added the Error Checking statements to the function
'|  V1.0:
'| The current variables are:
'|
'| strDirectory - We specify the Folder Path
'| dtStartingDate - It is is required a starting criteria
'| dtEndingdate - It is is required a Ending criteri

上一个:ASP的错误处理
下一个:VBS、ASP代码语法加亮显示的类 (二)

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,