这批代码:
:: File name: jjlist.bat (normally, must be in system path)
::
:: Purpose:
:: batch that lists date/time, justified size and full path and file name.
:: that goes to the screen or into a named file in current directory (folder)
::
:: To use, at the command line type:
:: jjlist *.* [or *.jpg etc]
:: to direct output to screen.
:: or
:: jjlist *.* outfilename.txt
::
:: author: eliasrk(at)gmail.com
::
@echo off
set outfile=%2
if "%1x"=="x" goto :end
if NOT "%2x"=="x" goto :out2file
:
:out2screen
for /r %%I in (%1) do if NOT "%%~tI" == "" call :loop4screen "%%~tI" "%%~zI" "%%I"
goto :end
:
:loop4screen
set Sz= %~2
echo %~1 %Sz:~-10% %~3
goto :end
:
:out2file
for /r %%I in (%1) do if NOT "%%~tI" == "" call :loop4fileOut "%%~tI" "%%~zI" "%%~xI" "%%I"
goto :end
:
:loop4fileOut
set Sz= %~2
set Ex=%~3 x
:echo %~1 %Sz:~-10% %Ex:~0,8% %~4 >> %outfile%
echo %~1 %Sz:~-10% %~4 >> %outfile%
goto :end
:
:end
Run Code Online (Sandbox Code Playgroud)
只要设置了这些注册表项:
[various] "\Control Panel\International" "iTime"="1"
[various] "\Control Panel\International" "iTLZero"="1"
[various] "\Control Panel\International" "sTimeFormat"="HH:mm:ss"
[various] "\Control Panel\International" "sShortDate"="yyyy-MM-dd"
Run Code Online (Sandbox Code Playgroud)
生成此表单的日期字符串可排序列表:
2013-04-16 13:35 1293 D:\Documents\T_Args\Drafts\2013_04_15\1st_circle_claim.txt
2013-04-16 11:51 2110 D:\Documents\T_Args\Drafts\2013_04_15\sources_01.txt
2012-10-08 10:45 13599 D:\Documents\T_Args\images_temp\taut_faq_working\new_tautology.txt
2013-02-05 12:54 8829 D:\Documents\T_Args\Popper\Objective_Knowledge\pages.txt
2013-02-05 11:36 8835 D:\Documents\T_Args\Popper\Objective_Knowledge\pages_org.txt
Run Code Online (Sandbox Code Playgroud)
自写这批文以来,我发现了两个问题,我想知道如何纠正:
1)当文件名中有"&"时,会生成一条错误消息,指示&之后的字符串被视为"命令".我希望这些文件名能够正常处理.
2)如果我在dir结构中列出了"jjlist*.doc"的输出就可以了,但是如果我提供一个完全限定的路径,就像"jjlist d:\ documents*.doc"那样没有输出.这可以修复吗?
谢谢你的帮助.
这很慢,但它适用于任何区域设置。需要XP专业版及以上版本。
文件名中的任何 & 字符都可以正常处理,但路径\文件名中的 % 和 ^ 会导致问题。
可以使用命令行上的路径\文件规范以及日志文件名。
:: Syntax: mybatchfile [d:\path\[filespec]] [[d:\path\]logfile.txt]
:: date time size filename
@echo off
for /f "delims=" %%a in ('dir "%~1" /b /s /a-d') do call :next "%%a" "%~2"
if "%~2"=="" pause
goto :EOF
:next
set "file=%~1"
set "file=%file:\=\\%"
WMIC DATAFILE WHERE name="%file%" get lastmodified,size|find ".">file.tmp
for /f "tokens=1,2" %%a in (file.tmp) do set size=%%a&set dt=%%b
set dt=%dt:~0,4%-%dt:~4,2%-%dt:~6,2% %dt:~8,2%:%dt:~10,2%
set size= %size%
set size=%size:~-18%
for %%a in ("%dt% %size% %~1") do echo %%~a
if not "%~2"=="" for %%a in ("%dt% %size% %~1") do >>"%~2" echo %%~a
del file.tmp
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
169 次 |
| 最近记录: |