htm(l)转txt(支持文件夹/保持原文件夹结构)_input

--------------------------------------代码----------

htm文件夹(txt放在同目录下的htm2txt文件夹中)
<input type=file id=htm_folder><br>
用htm标题做txt文件名(不处理同名文件,直接覆盖)<input type=checkbox id=txt_rn><br>
<input type=button id=doing onclick = "go(this);" value="开始转换">
<input type=button onclick = "location.reload();" value="停止"><br>
进度提示框<br>
<textarea id=tip style="width:100%;height:100px;">
</textarea>
<iframe id=win style="display:none;width:0px; height:0px;"></iframe>
<script>
var htm_path = new Array();
var txt_folder = 'htm2txt';
var htm_path_a = null;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var loader;function go(obj)
{
   if ( (htm_folder.value == "")  )
   {
      return alert("htm文件夹未选择!");
   }
   
   obj.value = "转换中...请稍候";
   obj.disabled = true;
   
   get_files_folder_first(htm_p_path());
}function get_files_folder_first(folderspec)
{
   var fc = new Enumerator(fso.GetFolder(folderspec).SubFolders);
   
   for (; !fc.atEnd(); fc.moveNext())
   {
      htm_path[htm_path.length]= fc.item();
   }  
   
   if (!fso.FolderExists(htm_p_path() + '//' + txt_folder))
   {
                fso.CreateFolder(htm_p_path() + '//' + txt_folder);
   }
   
   txt_path = fso.GetAbsolutePathName(htm2txt_path(folderspec));
   
   if (!fso.FolderExists(txt_path))
   {
                fso.CreateFolder(txt_path);
   }
   
   fc = new Enumerator(fso.GetFolder(folderspec).files);
   htm_path_a = new Array();
   for (; !fc.atEnd(); fc.moveNext())
   {
      htm_path_a[htm_path_a.length] = fc.item();
   }
   
   setTimeout('htm2txt();',1000);
}function htm_p_path()
{
   return fso.GetParentFolderName(htm_folder.value) + '';
}function htm2txt_path(folderspec)
{
   folderspec = folderspec + '';
   var new_p = htm_p_path() + '//' +  txt_folder + '//';
   return folderspec.replace(htm_p_path(), new_p);
}function get_files_folder(folderspec)
{
   var fc = new Enumerator(fso.GetFolder(folderspec).SubFolders);
   
   for (; !fc.atEnd(); fc.moveNext())
   {
      htm_path[htm_path.length]= fc.item();
   }
   
   txt_path = fso.GetAbsolutePathName(htm2txt_path(folderspec));
   
   if (!fso.FolderExists(txt_path))
   {
                fso.CreateFolder(txt_path);
   }
   
   fc = new Enumerator(fso.GetFolder(folderspec).files);
   htm_path_a = new Array();
   for (; !fc.atEnd(); fc.moveNext())
   {
      htm_path_a[htm_path_a.length] = fc.item();
   }
   
   setTimeout('htm2txt();',1000);
}function load_ok()
{
         if (win.document.readyState=="complete")
         {             
            var txt = win.document.documentElement.outerText;
            var fn = escape(win.document.title);
            
            
            if (txt_rn.checked)
            {
               var txt_tip = txt_path + '/' + fn + '.txt';
            }else
             {
                var txt_tip = txt_path + '/' + fso.GetBaseName(win.location.pathname) + '.txt';
             }
            
             fso.CreateTextFile(txt_tip).Write(txt);
             tip.value += document.title = "写入:" + txt_tip + '/n';
             setTimeout('htm2txt();',1000);
         }else
          {
             setTimeout('load_ok()',1000);
          }
}
        
function htm2txt()
{
   if (htm_path_a.length)
   {       
      var txt_tip = htm_path_a.shift();
      if (//.html?$/gi.test(txt_tip))
      {
        win.location.href = txt_tip;
        load_ok();
      }else
       {
          setTimeout('htm2txt();',1000);
       }
   }else if (htm_path.length)
    {
       setTimeout('get_files_folder(htm_path.shift());',1000);
    }else
     {
        doing.disabled = false;
        doing.value = "开始转换";
        alert("转换完成");
     }
}</script>

 

---------------------------------