gpt4 book ai didi

batch-file - 批处理递归列出具有日期时间和大小的路径文件名的两个问题

转载 作者:行者123 更新时间:2023-12-04 02:08:41 25 4
gpt4 key购买 nike

此批次代码:

    :: 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)如果我在要列出的目录结构中,说“jjlist *.doc”的输出是
很好,但是如果我提供完全限定的路径,如“jjlist
d:\documents*.doc"没有输出。可以解决这个问题吗?

谢谢你的帮助。

最佳答案

好又容易

保护&从解析中,您可以将其括在双引号中 使用 delayed expansion .例子:

@echo off&setlocalset "fname=nice & easy.txt"echo %fname%                        &rem error messageecho "%fname%"                      &rem output with quotessetlocal enabledelayedexpansion     echo !fname!                        &rem output without quotes

for /r

The for /r loop gets its start folder for the recursive search as parameter, this works:

for /r "d:\documents" %%I in (*.doc) do echo %%I

但是这个 不起作用 :
for /r %%I in (d:\documents\*.doc) do echo %%I

如果您需要一个路径作为递归搜索模式, 用这个 :
for /f "delims=" %%I in ('dir /b /a-d /s "d:\documents\*.doc"') do echo %%I

关于batch-file - 批处理递归列出具有日期时间和大小的路径文件名的两个问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16751210/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com