当前位置: 首页 > 图文教程 > 网络编程 > ASP > 用ASP实现远程将文件批量改名的代码

ASP
飞云写的防CC攻击的ASP程序插件 打包下载
随机调用n条数据的方法分析
一个强健 实用的asp+ajax二级联动菜单(有演示和附源程序打包下载)
asp 读取 utf-8格式文档并生成utf-8格式文档的乱码问题
实现纯真IP txt转mdb数据库的方法
用实现ASP批量删除目录及文件的代码
[ASP]RegExp对象提供简单的正则表达式支持功能使用说明
用ASP生成UTF-8网页文件的两种方法
asp利用fso给文件夹和文件改名的代码
asp 采集实战代码
解决采集时出现msxml3.dll 错误的方法
asp实现二进制字符串转换为Unicode字符串
asp 用InStr查找特定字符串的代码
[推荐]ASP编程通用函数收藏大全
去除HTML代码中所有标签的两种方法
asp Chr 函数 数字转字母的方法
asp快速开发方法之数据操作实例代码
asp去除所有的超级链接的两种方法 替换与正则
asp下实现截取字符串特定部分内容函数
asp下取得客户端IP地址函数 转换IP地址函数

用ASP实现远程将文件批量改名的代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 29 ::
收藏到网摘: n/a

<% @LANGUAGE = VBSCRIPT %>
<%Option Explicit%>
<%
'以下程序批量改名文件夹中的文件名,并将所有文件移动到新的文件夹;
Response.Write "<html>" & VbCrLf & "<head>" & VbCrLf
Response.Write "<title>批量文件改名</title>" & VbCrLf
Response.Write "</head>" & VbCrLf & "<body>" & VbCrLf
' 变量说明
Dim gbolGoProcedure
Dim strFromDir '源文件夹
Dim strTargetDir '目标文件夹
Dim objFS
Dim objRootFolder
Dim objFile
Dim strFileNameLen
Dim strPrevFileName
Dim strFileExt '文件扩展名
Dim strFileNameCount
Dim strNewFileName
Dim strRealCount '处理的文件数量
gbolGoProcedure = False
' 如果点击了开始按钮,进行以下处理
If (Request.Form("GoButton")) = " 开 始 " then
' 指定源文件夹、目标文件夹
 strFromDir = "D:test\"
 strTargetDir = "D:\test1\"
 ' 将处理文件数量设置为0
 strRealCount = 0
 Set objFS = Server.CreateObject("Scripting.FileSystemObject")
 Set objRootFolder = objFS.GetFolder(strTargetDir)
 '文件名的具体设置,这里设置为100001,表明文件名将从100001
 '开始,逐步递增,可以根据需要设置;
 strFileNameCount = 100001
For each objFile in objRootFolder.Files
 '对于特定的文件,不进行处理,可以根据需要设置;
 If objFile.Name = "Thumbs.db" then strFileNameCount = StrFileNameCount - 1
 strFileNameCount = strFileNameCount + 1
Next
Set objRootFolder = objFS.GetFolder(strFromDir)
For each objFile in objRootFolder.Files
 strFileNameLen = Len (objFile.Name)
 If Mid (objFile.Name,(strFileNameLen - 3),1) = "." then
  strFileExt = right(objFile.Name, 4)
 Else
  strFileExt = right(objFile.Name, 5)
 End If
 strPrevFileName = objFile.Name
 strNewFileName = strFileNameCount & strFileExt
 objFile.Move strTargetDir & strNewFileName
 Response.Write "源文件: " &strFromDir&strPrevFileName & " > 移动并改名为: " &strTargetDir& strNewFileName & "<br>" & vbCrLF
 strFileNameCount = strFileNameCount + 1
 strRealCount = strRealCount + 1
Next
 Response.Write "<p><b>一共处理: " & (strRealCount) & " 个文件</B>" & vbCrLf
 Set objRootFolder = Nothing
 Set objFS = Nothing
 gbolGoProcedure = True
End If
If gbolGoProcedure Then
 Response.Write("<p><b>批量文件批量移动和改名</b>") & vbCrLf
Else
 Response.Write("<center><br><form method=""post"" action=""FileNameConverter.asp""  ID=form1 name=""form1"">") & vbCrLf
 Response.Write("<input type=""SUBMIT"" value="" 开 始 "" ID=""GoButton""  name=""GoButton"">") & vbCrLf
 Response.Write("</form>") & vbCrLf
 Response.Write("<p><b>点击按钮对文件进行批量移动和改名</b></center>") & VbCrLf
End If
Response.Write "</body>" & VbCrLf & "</html>"
%>