重命名程序(可用js语法自定义命名格式)

<hta>
<head>
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<META HTTP-EQUIV="expires" CONTENT="0">
<title>实用程序</title>
</head>
<body scroll="auto" style="border:none; color:green;" bgcolor=black topmargin=0 leftmargin=0 rightmargin=0 bottommargin=0 >
<textarea id=show rows=10 style="height:40%; width:100%;"></textarea>
<textarea id=dofile rows=20 style="height:50%; width:100%;" title=请在这输入处理文件的方法>function (path){

//请在这输入处理文件的方法,其它不变。
//path 传入的文件路径
//显示信息框ID=show
//Ntxt21(oldpath,newpath); oldpath是取到的文件,newpath是已建立好的空白文本文件,此含数的作用是把oldpath追加到newpath后面,
//Ntxt21(path,"f:/new.txt")
//deltxt(oldtxt,txtformat)//把一个文件中的某个语句删除,oldtxt要删除的语句,txtformat文件格式,true或没或false

//fso.getfile(path).name  = prompt("",fso.GetBaseName(path)) + "." + fso.GetExtensionName(path);//改名
//fso.MoveFile(fso.gefile(path),"g:/mp3/" + fso.getBassName(path) + ".mid");//移动
//searchtxt(txt,path)//在文件中查找txt字符串
}</textarea>

源文件夹<input id="sourcefolder" type=file><input type=button value=获取全部文件夹 οnclick="getallfolder(sourcefolder.value)">

<input type=button value=处理所有文件 οnclick="doallfile()">
<input type=button id=clearall value=清除 οnclick="showtxt('已清除所有定时'); clearTimeout(fsotime)">
<SCRIPT language="javascript">
<!--

var fso = new ActiveXObject("Scripting.FileSystemObject");
var runtime = 1;
var foldersarray;
var fsotime;
var nowi;
var fp;
var theno;
var mydofile;

function showtxt(txt)
{
        show.focus();
        show.value = txt + "/n" +  show.value ;
}

function reportError(msg,url,line)
{
 alert("当前页的脚本发生错误: /n/n信息: " + msg + "/n/n行:" + line);
 return true;
}

window.onerror = reportError;

function getallfolder(path)
{
     if ( fso.fileExists(path) == false)
    {
         showtxt("出错啦!/n[" + path + "] 文件夹不存在!");
         return false;
      }
     
      path = fso.getparentfoldername(path);
   
      mygetfolder(path);
}

function mygetfolder(path){//自己递归时没参数

      if(path != undefined)
      {
         clearTimeout(fsotime);
         fp = null;
         nowi = -1;
         theno = 1;
         foldersarray = new Array(fso.getFolder(path).path);
         showtxt("开始获取文件夹.../n" + (theno++) + ": " + fso.getFolder(path).path);
      }

      try
      {
         if(fp == null)
         {
           fp = new Enumerator(fso.getFolder(foldersarray[++nowi]).subFolders);
         }
      }catch(e)
       {
         showtxt("取数组出错,原因是数组下标超出数组长度/n处理完成");
         theno = fp = nowi = null;
         return clearTimeout(fsotime);
       }

      if(!fp.atEnd())
      {
         showtxt( (theno++) + ": " + (foldersarray[foldersarray.length] = fp.item().path) );
         fp.moveNext();
      }
       else
       {
           fp = null;
       }

       fsotime = setTimeout("mygetfolder()",runtime);
        
}

function doallfile(start){
        
         try
         {
            foldersarray.length < 1;
         }catch(e)
          {
      return alert("请先点[获取全部文件夹]获取要处理的文件夹对象");
          }
        
         if(start == undefined)
         {
            nowi = 0;
            fp = null;
            theno = 1;
            try
            {
                eval("mydofile = " + dofile.value);
            }catch(e)
             {
                alert("自定义方法出错,请重新编写!详细错误请瞧信息框");
                showtxt(e.description);
             }
         }

         if(fp == null)
         {
            try
            {
               fp = new Enumerator(fso.getfolder(foldersarray[nowi++]).files);
            }catch(e)
             {
                showtxt("处理文件完成");
                theno = fp = nowi = null;
                return clearTimeout(fsotime);
             }
         }

         if(!fp.atEnd())
         {
           showtxt( (theno++) + ": " + fp.item().path );
           try
           {
                mydofile( fp.item().path );
           }catch(E)
            {
               showtxt("执行自定义处理文件方法时出错:" +  E.description);
            }
           fp.moveNext();
         }
          else
         {
           fp = null;
         }

       fsotime = setTimeout("doallfile(1)",runtime);

}

function Ntxt21(oldpath,newpath)
{

       if( fso.fileExists(newpath) == false)
          {
             showtxt("出错了:传入的newpath不存在请先建立后再试");
             return clearall.click();
          }

        var filep = fso.OpenTextFile(newpath, 8, false,true) ;
        filep.write( fso.OpenTextFile(oldpath,1,0,true).readAll() ); //打开新的文件并把旧文件追加到后面
        filep.close();
}

function deltxt(oldtxt,txtformat)
{
var oldfile = fso.openTextfile(path,1,0,txtformat);
var text = oldfile.readall();
oldfile.close();
oldfile = fso.openTextfile(path,2,0,txtformat);
oldfile.write(text.split(oldtxt));
oldfile.close();
}

function searchtxt(txt,path)
{
  if (//.(?:gif)|(?:jpg)$/gi.test(path))
  {
      return showtxt(path + "文件不是文本格式");
  }
 
   var oldfile = fso.openTextfile(path,1,0);

    if (oldfile.readall().indexOf(txt) > -1)
    {
        showtxt("在文件[" + path + "]中找到该字符串!");
    }else
     {
        showtxt("在文件[" + path + "]中找不到该字符串!");
     }
    
     oldfile.close();
     oldfile = null;
}
//-->
</SCRIPT>
</BODY>
</hta>
 
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值