CSDN博客

img runmin

生成文件夹文件列表。

发表于2004/6/24 8:46:00  1117人阅读

/**

  * Title:         File List Generator

  *

  * Description:

  * <pre>

  * </pre>

  *

  * Usage:

  * <pre>

  * 1. Save the code to a file named 'afile.js';

  * 2. Drag a Folder Icon on the 'afile.js'

  *    or run command 'cscript %path%/afile.js c:/windows/';

  * 3. Then find the 'index.htm' in the folder.

  * </pre>

  *

  * Version:  1.0

  * Author:        mruan(at)comgi.com

  * Copyright:     Freeware.

  */

 

     var fso = new ActiveXObject("Scripting.FileSystemObject");

 

     //   Get Folder path

     var strFolder = WScript.Arguments(0);

     var oFolder;

 

     //   Get Folder Object

     oFolder = fso.GetFolder(strFolder);

 

     //   Get Files and Generate HTML

     fc = new Enumerator(oFolder.files);

     s = "";

     for ( var i=0; !fc.atEnd(); fc.moveNext(),i++ )

     {

         s += "<tr>/n";

         s += "<td class='r" + i%2 + "'><a href='" + fc.item().Name + "'>";

         s += fc.item().Name;

         s += "</a></td>/n";

         s += "<td class='r" + i%2 + "'>";

         s += fc.item().Size;

         s += "</td>/n";

         s += "<td class='r" + i%2 + "'>";

         s += fc.item().Type;

         s += "</td>/n";

         s += "<td class='r" + i%2 + "'>";

         s += new Date(fc.item().DateLastModified).toLocaleString();

         s += "</td>/n";

         s += "</tr>/n";

     }

 

//   Create file

var oIndexFileStream = fso.CreateTextFile( strFolder + "//index.htm", true );

 

//   Generate HTML and write to file

oIndexFileStream.WriteLine("<HTML>");

oIndexFileStream.WriteLine("<HEAD>");

oIndexFileStream.WriteLine("<TITLE> File List Gernerator 1.0 </TITLE>");

oIndexFileStream.WriteLine("</HEAD>");

oIndexFileStream.WriteLine("<style>");

oIndexFileStream.WriteLine("td.head");

oIndexFileStream.WriteLine("{");

oIndexFileStream.WriteLine("     font-size: 12px;");

oIndexFileStream.WriteLine("     font-family: Tahoma;");

oIndexFileStream.WriteLine("     background-color: #8B8B8B;");

oIndexFileStream.WriteLine("}");

oIndexFileStream.WriteLine("td.r0");

oIndexFileStream.WriteLine("{");

oIndexFileStream.WriteLine("     font-size: 12px;");

oIndexFileStream.WriteLine("     font-family: Tahoma;");

oIndexFileStream.WriteLine("     background-color: #DDDDDD;  ");

oIndexFileStream.WriteLine("}");

oIndexFileStream.WriteLine("td.r1");

oIndexFileStream.WriteLine("{");

oIndexFileStream.WriteLine("     font-size: 12px;");

oIndexFileStream.WriteLine("     font-family: Tahoma;");

oIndexFileStream.WriteLine("     background-color: #FFFFFF;");

oIndexFileStream.WriteLine("}");

oIndexFileStream.WriteLine("</style>");

oIndexFileStream.WriteLine("<BODY>");

oIndexFileStream.WriteLine("");

oIndexFileStream.WriteLine("     <TABLE width='100%'>");

oIndexFileStream.WriteLine("     <TR>");

oIndexFileStream.WriteLine("          <TD class='head'><b>Name</b></TD>");

oIndexFileStream.WriteLine("         <TD class='head'><b>Size</b></TD>");

oIndexFileStream.WriteLine("         <TD class='head'><b>Type</b></TD>");

oIndexFileStream.WriteLine("         <TD class='head'><b>Date Modified</b></TD>");

oIndexFileStream.WriteLine("     </TR>");

oIndexFileStream.WriteLine(s);

oIndexFileStream.WriteLine("     </TABLE>");

oIndexFileStream.WriteLine("");

oIndexFileStream.WriteLine("</BODY>");

oIndexFileStream.WriteLine("</HTML>");

 

//   Open the file

new ActiveXObject("WScript.Shell").Run("iexplore " + strFolder + "//index.htm");

 

0 0

相关博文

我的热门文章

img
取 消
img