Chinaunix首页 | 论坛 | 博客
  • 博客访问: 351846
  • 博文数量: 89
  • 博客积分: 2919
  • 博客等级: 少校
  • 技术积分: 951
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-23 11:51
个人简介

好懒,什么都没写

文章分类

全部博文(89)

文章存档

2012年(3)

2011年(17)

2007年(20)

2006年(49)

我的朋友

分类: Python/Ruby

2011-04-07 09:54:22

获取指定目录及其子目录全部文件的文件名,修改时间,版本号码等信息。
注意,本处理只能处理EXE/DLL文件的版本号码,JAR等文件的版本号码暂不能获取。

该方法使用 dir 命令来获取文件列表,然后逐个文件循环处理。
    dir /a-d /b /s

重要的是,批处理貌似不能获取EXE/DLL等文件的版本号码,
所以这部分是由VBScript来完成的。

VBScript代码
  1. set objArgs=WSCRIPT.Arguments
  2. Set objFSO = CreateObject("Scripting.FileSystemObject")
  3. Wscript.Echo objFSO.GetFileVersion(objArgs(0))

批处理代码
  1. REM "setlocal enabledelayedexpansion" is very important w
  2. @echo off
  3. setlocal enabledelayedexpansion REM To get errorlevel correctly, we need delay expansion

  4. set made=YeChao& set title=FileList Generator
  5. title %title% %made% %date% %time:~0,8%
  6. REM mode con: cols=80 lines=50 & color 0A
  7. REM mode con: cols=80 lines=30
  8. REM set yy=2011& set mm=03& set dd=25
  9. set pnum=2
  10. :main
  11. cls
  12. echo. **********************************************************
  13. echo. Function:%title%
  14. echo. Made by:%made% %yy% Year %mm% Month %dd% Day
  15. echo. Generating File List
  16. echo. **********************************************************

  17. ping /n %pnum% 127.1 > nul
  18. REM color 70
  19. ::ping /n %pnum% 127.1 > nul
  20. if exist YeChao_FileList.csv del YeChao_FileList.csv

  21. REM set folder=D:\IOFollow\YeChao\MyTestBat\EXEFile
  22. REM set folder=D:\YeChao\std\1.3.9.1\Release\REzInst1391
  23. echo Please input file name or folder:
  24. set /p folder=
  25. set strFolder=%folder%
  26. :loopLen
  27. set /a a+=1
  28. if not "!strFolder:~%a%,1!" equ "" goto :loopLen
  29. set /a a+=1
  30. echo.
  31. echo CurrentDir:%~dp0
  32. echo WorkingDir:%folder%
  33. echo CurrentDir len is %a%

  34. echo.
  35. echo Please wait...
  36. echo.
  37. echo RelativePathname,FileName,ModifiedTime,FileVersion,Size(Byte) >>YeChao_FileList.csv
  38. for /f "delims=""" %%i in ('dir /a-d /b /s %folder% 2^>nul') do (
  39. for /f "tokens=1,2" %%j in ('dir /a /tc "%%i" ^| findstr "%%~nxi"') do (
  40. if not "%%j"=="Directory" ( REM Because subfolder's file maybe duplicated,check it before output it

  41. echo %%~nxi|findstr "exe\>" >nul 2>nul
  42. set relativepath=%%~dpi
  43. set relativepath=!relativepath:~%a%!
  44. set curfile=!relativepath!%%~nxi

  45. REM Absolute path is %%~dpi%%~nxi

  46. if !errorlevel! equ 0 (
  47. for /f "delims=" %%k in ('cscript //nologo getFileVerStr.vbs %%i') do ( echo !curfile!,%%~nxi,%%~ti,%%k,%%~zi>>YeChao_FileList.csv )
  48. echo filetype:exe !curfile!
  49. ) else (
  50. echo %%~nxi|findstr "dll\>" >nul 2>nul
  51. REM echo errorlevel = !errorlevel!
  52. if !errorlevel! equ 0 (
  53. echo filetype:dll !curfile!
  54. for /f "delims=" %%m in ('cscript //nologo getFileVerStr.vbs %%i') do ( echo !curfile!,%%~nxi,%%~ti,%%m,%%~zi>>YeChao_FileList.csv )
  55. ) else (
  56. echo filetype:general !curfile!
  57. echo !curfile!,%%~nxi,%%~ti,,%%~zi>>YeChao_FileList.csv
  58. )
  59. )
  60. )

  61. REM for /f "delims=, " %%k not in (*.exe) do ( echo %%~nxi,%%~dpi%%~nxi,%%~ti, ,%%~zi>>YeChao_FileList.csv )
  62. REM for /f "delims=" %%k in (' echo %%i | findstr .exe ') do ( echo %%~nxi,%%~dpi%%~nxi,%%~ti,%%j,%%~zi>>YeChao_FileList.csv )

  63. REM for /f "delims=" %%j in ('cscript //nologo getFileVerStr.vbs %%i') do ( echo %%~dpi%%~nxi,%%~nxi,%%~ti,%%j,%%~zi>>YeChao_FileList.csv )
  64. REM set strVer = GetFileVersion.vbs


  65. REM if "%%j"=="Directory" echo Directory:%%i
  66. REM echo.>>YeChao_FileList.csv
  67. REM echo File name:%%~nxi,%%~zi,%%~dpi,%%j %%k,%%~ti>>YeChao_FileList.csv
  68. REM echo Size:%%~zi Byte>>YeChao_FileList.csv
  69. REM echo Path:%%~dpi>>YeChao_FileList.csv
  70. REM echo Create time:%%j %%k>>YeChao_FileList.csv
  71. REM echo Modify time:%%~ti>>YeChao_FileList.csv
  72. REM echo %%~nxi,%%~dpi%%~nxi,%%~zi,%%~ti>>YeChao_FileList.csv

  73. )
  74. )
  75. echo Finished!!! getFileVerStr.vbs.txt    FileListGenerator.bat.txt  
  76. REM ping /n %pnum% 127.1 > nul

  77. pause;
  78. REM start YeChao_FileList.csv


阅读(3736) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~