获取指定目录及其子目录全部文件的文件名,修改时间,版本号码等信息。
注意,本处理只能处理EXE/DLL文件的版本号码,JAR等文件的版本号码暂不能获取。
该方法使用 dir 命令来获取文件列表,然后逐个文件循环处理。
dir /a-d /b /s
重要的是,批处理貌似不能获取EXE/DLL等文件的版本号码,
所以这部分是由VBScript来完成的。
VBScript代码
- set objArgs=WSCRIPT.Arguments
-
Set objFSO = CreateObject("Scripting.FileSystemObject")
-
Wscript.Echo objFSO.GetFileVersion(objArgs(0))
批处理代码
- REM "setlocal enabledelayedexpansion" is very important w
-
@echo off
-
setlocal enabledelayedexpansion REM To get errorlevel correctly, we need delay expansion
-
-
set made=YeChao& set title=FileList Generator
-
title %title% %made% %date% %time:~0,8%
-
REM mode con: cols=80 lines=50 & color 0A
-
REM mode con: cols=80 lines=30
-
REM set yy=2011& set mm=03& set dd=25
-
set pnum=2
-
:main
-
cls
-
echo. **********************************************************
-
echo. Function:%title%
-
echo. Made by:%made% %yy% Year %mm% Month %dd% Day
-
echo. Generating File List
-
echo. **********************************************************
-
-
ping /n %pnum% 127.1 > nul
-
REM color 70
-
::ping /n %pnum% 127.1 > nul
-
if exist YeChao_FileList.csv del YeChao_FileList.csv
-
-
REM set folder=D:\IOFollow\YeChao\MyTestBat\EXEFile
-
REM set folder=D:\YeChao\std\1.3.9.1\Release\REzInst1391
-
echo Please input file name or folder:
-
set /p folder=
-
set strFolder=%folder%
-
:loopLen
-
set /a a+=1
-
if not "!strFolder:~%a%,1!" equ "" goto :loopLen
-
set /a a+=1
-
echo.
-
echo CurrentDir:%~dp0
-
echo WorkingDir:%folder%
-
echo CurrentDir len is %a%
-
-
echo.
-
echo Please wait...
-
echo.
-
echo RelativePathname,FileName,ModifiedTime,FileVersion,Size(Byte) >>YeChao_FileList.csv
-
for /f "delims=""" %%i in ('dir /a-d /b /s %folder% 2^>nul') do (
-
for /f "tokens=1,2" %%j in ('dir /a /tc "%%i" ^| findstr "%%~nxi"') do (
-
if not "%%j"=="Directory" ( REM Because subfolder's file maybe duplicated,check it before output it
-
-
echo %%~nxi|findstr "exe\>" >nul 2>nul
-
set relativepath=%%~dpi
-
set relativepath=!relativepath:~%a%!
-
set curfile=!relativepath!%%~nxi
-
-
REM Absolute path is %%~dpi%%~nxi
-
-
if !errorlevel! equ 0 (
-
for /f "delims=" %%k in ('cscript //nologo getFileVerStr.vbs %%i') do ( echo !curfile!,%%~nxi,%%~ti,%%k,%%~zi>>YeChao_FileList.csv )
-
echo filetype:exe !curfile!
-
) else (
-
echo %%~nxi|findstr "dll\>" >nul 2>nul
-
REM echo errorlevel = !errorlevel!
-
if !errorlevel! equ 0 (
-
echo filetype:dll !curfile!
-
for /f "delims=" %%m in ('cscript //nologo getFileVerStr.vbs %%i') do ( echo !curfile!,%%~nxi,%%~ti,%%m,%%~zi>>YeChao_FileList.csv )
-
) else (
-
echo filetype:general !curfile!
-
echo !curfile!,%%~nxi,%%~ti,,%%~zi>>YeChao_FileList.csv
-
)
-
)
-
)
-
-
REM for /f "delims=, " %%k not in (*.exe) do ( echo %%~nxi,%%~dpi%%~nxi,%%~ti, ,%%~zi>>YeChao_FileList.csv )
-
REM for /f "delims=" %%k in (' echo %%i | findstr .exe ') do ( echo %%~nxi,%%~dpi%%~nxi,%%~ti,%%j,%%~zi>>YeChao_FileList.csv )
-
-
REM for /f "delims=" %%j in ('cscript //nologo getFileVerStr.vbs %%i') do ( echo %%~dpi%%~nxi,%%~nxi,%%~ti,%%j,%%~zi>>YeChao_FileList.csv )
-
REM set strVer = GetFileVersion.vbs
-
-
-
REM if "%%j"=="Directory" echo Directory:%%i
-
REM echo.>>YeChao_FileList.csv
-
REM echo File name:%%~nxi,%%~zi,%%~dpi,%%j %%k,%%~ti>>YeChao_FileList.csv
-
REM echo Size:%%~zi Byte>>YeChao_FileList.csv
-
REM echo Path:%%~dpi>>YeChao_FileList.csv
-
REM echo Create time:%%j %%k>>YeChao_FileList.csv
-
REM echo Modify time:%%~ti>>YeChao_FileList.csv
-
REM echo %%~nxi,%%~dpi%%~nxi,%%~zi,%%~ti>>YeChao_FileList.csv
-
-
)
-
)
-
echo Finished!!! getFileVerStr.vbs.txt FileListGenerator.bat.txt
-
REM ping /n %pnum% 127.1 > nul
-
-
pause;
-
REM start YeChao_FileList.csv
阅读(3693) | 评论(0) | 转发(0) |