批处理生成 HTML格式 的文件列表

简爱代码2013-1-1 19:19116064
复制保存为 bat 即可

可修改 文件目录

不修改  默认生成当前路径下的文件列表

@echo off
title 生成文件列表 by 简爱
mode con: cols=30 lines=4
::
:: 生成 html 文件列表 转换文件大小为合适单位
:: 拿去修改  记得保留 简爱 名字
::
:: 设置目录  留空为当前
set dir=



set sj=%date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%:%time:~3,2%:%time:~6,2%
set file=文件列表_%dir%_%sj%.html
echo ^<!DOCTYPE html^>^<html^> >"%file%"
echo ^<meta charset=gb2312 /^>^<body bgcolor="#CCCCCC"^>^<div align="center"^>^<br/^> >>"%file%"
echo ^<h2^>文件列表 生成 by 简爱^</h2^>^<h4^>生成时间:%sj%^</h4^> >>"%file%"
echo ^<table width="95%%" border="1" align="center" cellpadding="5" cellspacing="0" style="font-family: 微软雅黑; color:#008000; font-size:14px;"^> >>"%file%"
echo ^<tr^>^<td width="40px"^>序号^</td^>^<td width="200px"^>文件名称^</td^>^<td width="135px"^>文件大小^</td^>^<td^>完整路径^</td^>^</tr^> >>"%file%"
setlocal enabledelayedexpansion
cls
echo;
echo   请稍后 ... ...
set n=
for /f "delims=" %%a in ('dir /s /b /a-d %dir%') do (
  set /a n+=1
  set /a z_size+=%%~za
  call :size %%~za
  echo ^<tr^>^<td^>!n!^</td^>^<td^>%%~nxa^</td^>^<td^>!size! ^(%%~za^)^</td^>^<td^>%%a^</td^>^</tr^> >>"%file%"
  cls
  echo;
  echo 文件个数: !n!
  echo 总大小: !z_size!
)
call :size !z_size!
del %temp%\js.vbs
echo ^</table^>^<h4^>文件总个数: !n! 个 ^&nbsp; ^&nbsp; ^&nbsp; 文件总大小: %size% ^(!z_size! 字节^)^</h4^> >>"%file%"
echo ^<br/^>^<br/^>Powered by ^<a href="http://gouji.org" target="_blank"^>GouJi.org^</a^> ^&nbsp; ^<a target="_blank" href="http://sighttp.qq.com/authd?IDKEY=83e9ce6969512c3981e5fcc63b2ebba0b92ec9494ace74b5"^>简爱^</a^>^<br/^>^<br/^>^</div^>^</body^>^</html^> >>"%file%"
cls
echo;
echo   生成完毕 按任意键打开
pause >nul
start "" "%file%"

exit
:size
if %1 geq 1073741824 (
  call :js %1 1073741824 GB
  goto :eof
)
if %1 geq 1048576 (
  call :js %1 1048576 MB
  goto :eof
)
if %1 geq 1024 (
  call :js %1 1024 KB
  goto :eof
)
set size=%1 Byte
goto :eof

:js
::除法保留小数 利用VBS 结果 为四舍五入
::速度慢 计算准确 好像不容易退出
if not exist %temp%\js.vbs (
  echo wscript.echo round^(wscript.arguments^(0^)/wscript.arguments^(1^),2^) >%temp%\js.vbs
)
for /f %%a in ('cscript //nologo %temp%\js.vbs %1 %2') do set size=%%a %3
goto :eof

本文出自简爱博客,转载时请注明出处及相应链接。

评论

  1. 七速2014-11-18 22:17回复

    非常不错!

  2. 电脑后勤部2013-07-15 18:47回复

    非常不错!思路很好

  3. sbobet wap username2013-05-20 01:27回复

    好的评语

  4. wap agent sbobet com2013-05-18 22:22回复

    你好

发表评论

电子邮件地址不会被公开。必填项已用*标注