乐府诗个人博客 >> ASP >> 使用asp 制作文件批量改名

使用asp 制作文件批量改名

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>asp文件批量改名</title>
<script language="javascript">
function chksubmit()
{
 if (document.form1.e.value == "")        
  {        
    window.alert("文件路径必须填写-相对路径");        
    document.form1.e.focus();        
    return (false);} 
 
 }
</script>
<style type="text/css">
<!--
.STYLE4 {font-size: 12px}
.STYLE6 {font-size: 12px; font-weight: bold; }
.STYLE8 {font-size: 14px}
.STYLE9 {color: #FF0000}
-->
</style>
<script type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>
<%action=request("action")
if action="save" then
call save()
end if
%>
<body>
<table width="90%" border="0" align="center">
 <form id="form1" name="form1" method="post" action="rename.asp" onSubmit="return chksubmit();"> <tr>
    <td colspan="2" class="STYLE2"><div align="center"><span class="STYLE6">ASP批量改文件名</span></div></td>
  </tr>
  <tr>
    <td width="38%" class="STYLE2"><div align="right" class="STYLE4">文件名前缀:</div></td>
    <td width="62%" class="STYLE2"><input name="a" type="text" id="a" /></td>
  </tr>
  <tr>
    <td class="STYLE2"><div align="right" class="STYLE4">文件名后缀:</div></td>
    <td class="STYLE2"><input name="b" type="text" id="b" /></td>
  </tr><input type=hidden name=action value=save>
  <tr>
    <td class="STYLE2"><div align="right" class="STYLE4">文件夹(相对路径):
    </div>
    <div align="right" class="STYLE2"></div></td>
    <td class="STYLE2"><input name="e" type="text" id="e" size="40" /> 
      <span class="STYLE4">如"../pic"不要在最后面加"/",如"../pic/"不行</span></td>
  </tr>
    <tr>
    <td class="STYLE2"><div align="right" class="STYLE4">文件类型:
    </div>
      <div align="right" class="STYLE2"></div></td>
    <td class="STYLE2"><select name="f" id="f" onchange="MM_jumpMenu('parent',this,0)">
      <option value="gif">gif</option>
      <option value="jpg">jpg</option>
      <option value="png">png</option>
      <option value="zip">zip</option>
      <option value="rar">rar</option>
      <option value="exe">exe</option>
      <option value="txt">txt</option>
      <option value="doc">doc</option>
      <option value="xls">xls</option>
      <option value="htm">htm</option>
      <option value="asp">asp</option>
      <option value="php">php</option>
      <option value="jsp">jsp</option>
          </select></td>
  </tr>
  <tr>
    <td colspan="2"><div align="center" class="STYLE2">
      
        <input type="submit" name="Submit" value="改名" />
      
      </div></td>
  </tr>
  <tr>
    <td colspan="2"><div align="center"><span class="STYLE8">如果:in_1_p.gif , in_2_p.gif , in_3_p.gif , in_4_p.gif , in_5_p.gif , in_6_p.gif , in_7_p.gif , in_8_p.gif<br />
      "in"表示前缀<br />
      "p"表示后缀<br />
      前缀和后缀可以不填写,<span class="STYLE9">相对路径必须填写.<br />
      <strong>需要空间支持FSO</strong><br />
      <br />
      </span></span></div></td>
  </tr>
 </form>
</table>
</body>
</html>
<%
'a前缀
'b后缀
'e文件夹(相对路径)
sub save()
a=request("a")
b=request("b")
ee=request("e")
f=request("f")
set fso=Server.CreateOBject("Scripting.FileSystemObject")
e=server.mappath(ee)
set fc=fso.getfolder(e).files
for each f1 in fc
  aa=aa&"|"&server.mappath(ee&"/"&f1.name)
next
aa=split(aa,"|")
for i=1 to ubound(aa)
  fso.movefile ""&aa(i)&"",""&server.mappath(ee&"/"&a&i&b&"."&f)&""
  response.write ">>>"&aa(i)&"<br>"
next
Response.write "<script>alert('修改成功');location.href='rename.asp';</script>"
Response.end
end sub
'-------------------------------------------------------------------------------------------------------
%>

下列内容与批量有着内在的联系,建议您一并阅读。

公益广告