欢迎光临
我们一直在努力

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

建站超值云服务器,限时71元/月

删除文件
<%
|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 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 criteria
| intqued   – it decides if we using the queue directory or not (0 – no / 1 – yes)
|
| example:
|  call fileferret(strdirectory, dtstartingdate, dtendingdate,intqued)
| normal usage:
|  call fileferret("/desktop/asp_odds/generic_funcs/test/","19/02/2001 00:00:00","20/02/2001 16:16:34",0)
|  when using on queued directory:
|  call fileferret("/desktop/asp_odds/generic_funcs/test/","19/02/2001 00:00:00","20/02/2001 16:16:34",1)

function fileferret(byval strdirectory,byval dtstartingdate,byval dtendingdate,byval intqued)
dim intbadcounter it will count how many bad emails there are
dim intquedcounter

intbadcounter = 0
intquedcounter = 0

———————–[ start error checking ]—————————
checks if there is a ( directory )defined in the parameter
if strdirectory = "" or isnull(strdirectory) then
  response.write("the parameter for directory is missing – it is a required parameter!")
  response.end
end if

checks if the ( starting date ) parameter is missing
if dtstartingdate = "" or isnull(dtstartingdate) then
  response.write("the starting date parameter is missing – it is a required parameter!")
  response.end
end if

checks if the ( ending date ) parameter is missing
if dtendingdate = "" or isnull(dtendingdate) then
  response.write("the ending date parameter is missing – it is a required parameter!")
  response.end
end if

checks if the ( intqued ) parameter is missing
if intqued = "" or isnull(intqued) then
  response.write("the intqued parameter is missing – it is a required parameter!")
  response.end
end if
———————–[ end error checking ]—————————

set fs = createobject("scripting.filesystemobject")
set f = fs.getfolder(server.mappath(strdirectory))
set fc = f.files

%>
<h1><%=strdirectory%></h1>
<hr>
<table border="0" cellpadding="0" cellspacing="3" align="center">

<%
for each file in fc
intquedcounter = intquedcounter + 1
   it checks if it is in between a certain time limite
  if formatdatetime(file.datecreated ,0) >= dtstartingdate and formatdatetime(file.datecreated ,0) <= dtendingdate then

    checks if it is an email
   if right(file.name,4) = ".msg" or  right(file.name,4) = ".eml" then
    img = "img/email.gif"
   end if

    checks if it is a log file or a text file
   if right(file.name,4) = ".log" or  right(file.name,4) = ".txt" then
    img = "img/txt.jpg"
   end if

    checks if it is a bad email file
   if right(file.name,4) = ".bad" then

     increases the bad emails counter by 1
       intbadcounter = intbadcounter + 1
    img = "img/emailbad.gif"
   end if
%>
<tr>
<td align="center"><img src="<%=img%>"></td>
<td><a href=<%=strdirectory & file.name%>><%=file.name%></a></td>
<td><%=formatdatetime(file.datecreated ,0)%></td>
</tr>
<%
  end if
next

%>
<tr>
<td>there are </td><td><b><%=intbadcounter%></b> bad emails.</td>
</tr>
<%
we check if we using the queue directory (0 – no / 1 – yes)
if intqued = 1 then %>
<tr>
<td>there are </td><td><b><%=intquedcounter%></b> emails awating to be sent.</td>
</tr>
<% end if %>
</table>

<%
end function
%>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 一组FSO相关FUNCTION,常用代码(也常有人问,重复问)
分享到: 更多 (0)

相关推荐

  • 暂无文章