求高手帮忙,如何整理电脑中指定路径的所有word文档,生成一个word文档带所有文档链接的目录?
谢谢了!
程序代码:
static void Main ( string[ ] args ) { string yourPath = @"";//你要整理的目录 bool blnSubDirectories = false;//如果同时要整理子目录下的文件就改为true StreamWriter sw = new StreamWriter ( "Output.html", false, Encoding.Default ); string[ ] docs = Directory.GetFiles ( yourPath, "*.doc", blnSubDirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly ); string htmlTemplete = "<tr><td><a href='{0}'>{1}</a></td><td>{2}</td><td>{3}</td></tr>"; sw.WriteLine ( "<Html><table><tr>文件名<td></td><td>大小(K)</td><td>时间</td></tr>" ); foreach ( string doc in docs ) { string wordname = Path.GetFileName ( doc ); FileInfo file = new FileInfo ( doc ); sw.WriteLine ( string.Format ( htmlTemplete, doc, wordname, file.Length / 1024, file.LastWriteTime ) ); } sw.WriteLine ( "</table></html>" ); sw.Close ( ); sw.Dispose ( ); }上面代码填上你的文档路径,运行一下,把Output.html在WORD中打开,另存为DOC就行了