标题: 用ASP实现远程批量文件改名
问天
元帅
Rank: 1


元帅勋章 终身成就勋章
UID 11493
精华 187
积分 34221
帖子 33355
威望 91
金币 13148
热心 2619
阅读权限 100
注册 2006-4-7
状态 离线
用ASP实现远程批量文件改名

<% @LANGUAGE = VBSCRIPT %>
<%Option Explicit%>
<%
'以下程序批量改名文件夹中的文件名,并将所有文件移动到新的文件夹;
Response.Write "<html>" &;amp; VbCrLf &;amp; "<head>" &;amp; VbCrLf
Response.Write "<title>批量文件改名</title>" &;amp; VbCrLf
Response.Write "</head>" &;amp; VbCrLf &;amp; "<body>" &;amp; 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 &;amp; strFileExt

 objFile.Move strTargetDir &;amp; strNewFileName

 Response.Write "源文件: " &;amp;strFromDir&;amp;strPrevFileName &;amp; " > 移动并改名为: " &;amp;strTargetDir&;amp; strNewFileName &;amp; "<br>" &;amp; vbCrLF  
 strFileNameCount = strFileNameCount   1
 strRealCount = strRealCount   1

Next

 Response.Write "<p><b>一共处理: " &;amp; (strRealCount) &;amp; " 个文件</B>" &;amp; vbCrLf

 Set objRootFolder = Nothing
 Set objFS = Nothing

 gbolGoProcedure = True

End If

If gbolGoProcedure Then
 Response.Write("<p><b>批量文件批量移动和改名</b>") &;amp; vbCrLf

Else
 Response.Write("<center><br><form method=""post"" action=""FileNameConverter.asp""  ID=form1 name=""form1"">") &;amp; vbCrLf
 Response.Write("<input type=""SUBMIT"" value="" 开 始 "" ID=""GoButton""  name=""GoButton"">") &;amp; vbCrLf
 Response.Write("</form>") &;amp; vbCrLf
 Response.Write("<p><b>点击按钮对文件进行批量移动和改名</b></center>") &;amp; VbCrLf
End If

Response.Write "</body>" &;amp; VbCrLf &;amp; "</html>"

%>

网友 问天 签名 - 网友社区 请您回个帖。谢谢
PR查询 免费域名 免费空间
顶部
[广告] 免费域名(Free Subdomain) 免费空间(Free hosting) PR查询(Google Pagerank)



当前时区 GMT+8, 现在时间是 2008-11-24 00:20
信产部ICP备案:京ICP备05066424号 北京市公安局网监备案:1101050648号

Powered by Discuz! 5.5.0
清除 Cookies - 联系我们 - 网友俱乐部 - Archiver - WAP