用ASP实现远程将文件批量改名的代码
程序员文章站
2022-08-06 10:31:32
<% @language = vbscript %><%option explicit%><%'以下程序批量改名文件夹中的文件名,并将所有文件移动到新的文件夹;respon...
<% @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>"
%>
<%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>"
%>
上一篇: 数据库复习整理