此批代码:
:: 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
前提是设置了这些注册表项:
[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"
生成这种形式的日期字符串可排序列表:
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
自从写了这批我发现了两个问题,我想知道如何纠正:
1) 当文件名中有“&”时,会生成一条错误消息,指示 & 后面的字符串被视为“命令”。我希望正常处理此类文件名。
2) 如果我在要列出的 dir 结构中,say "jjlist *.doc" 的输出很好,但是如果我在 "jjlist d:\documents*.doc" 中提供完全限定的路径,则没有输出。这可以解决吗?
谢谢你的帮助。