包含 2 个 ghost 条目的子文件夹列表我如何避免它们?

List of subfolders with 2 ghost entries how can I avoid them?

我使用 bat 文件对目录中的子文件夹列表进行了排序,但是名为“.”的 2 个文件夹是什么? 1 点和“..”2 点?实际上它们不存在于 windows 资源管理器中,最重要的是我如何避免在列表中显示它们?

@echo off
setlocal EnableExtensions EnableDelayedExpansion
> ".\Utils\Check last modified Profile.txt" (
    for /F "delims=" %%D in ('
    dir %APPDATA%\Mozilla\Firefox\Profiles\  /A /all-D /TW /A:D /O:-DE 
') do (
    rem print each item:        
       echo %%~D %
      )
)
endlocal

图片在这里 > https://imgur.com/8XyQk6q

. 是当前目录。 .. 是它的父目录。

Explorer 隐藏了它们。

Dir C:\windows\.\.\..

您可以使用并添加此开关/B

@echo off
@for /F "delims=" %%D in ('
    dir %APPDATA%\Mozilla\Firefox\Profiles\ /A /all-D /TW /A:D /O:-DE /B
') do (
    echo %%~D
    )
dir %APPDATA%\Mozilla\Firefox\Profiles\  /A /all-D /TW /A:D /O:-DE ^|findstr /v /e /L /c:"."

对我有用。

dir 输出被发送到 findstr,它允许通过不以 (/v) 结尾 (/e) 的行以文字 (/L) 字符串“.”

无法创建以 .

结尾的目录

我相信我不需要对属性选择规范做进一步的评论。

需要 ^ 才能将管道应用到 dir 命令,而不是 for

我不会对指定的属性选择做进一步评论。

我决定 post 这是因为现有的答案似乎对 Dir 命令使用了同样疯狂和错误的选项。以下示例使用适当的 findstr.exe 方法从您的列表中删除 ... 目录条目,并根据最近修改到最不最近进行排序。我已经包含了 findstr.exe 的完整路径,以消除 %PATH% and/or %PATHEXT% 修改无法找到它的可能性。

如果您想要相同的输出格式,那么这应该适合您:

@For /F "Tokens=1*Delims=:" %%G In ('"Dir "%AppData%\Mozilla\Firefox\Profiles" /AD/O-DE 2>NUL|%SystemRoot%\System32\findstr.exe /ELNV ".""')Do @Echo(%%H

如果你不需要空行,这应该为你省略那些:

@For /F "Delims=" %%G In ('"Dir "%AppData%\Mozilla\Firefox\Profiles" /AD/O-DE 2>NUL|%SystemRoot%\System32\findstr.exe /ELV ".""')Do @Echo %%G

如果您只需要目录名称行,那么也许这会让您满意:

@For /F EOL^=^ Delims^= %%G In ('"Dir "%AppData%\Mozilla\Firefox\Profiles" /AD/O-DE 2>NUL|%SystemRoot%\System32\findstr.exe /ELV ".""')Do @Echo %%G