通过 Windows DIR 仅显示带有链接信息的文件夹名称

通过 Windows DIR 仅显示带有链接信息的文件夹名称

我如何才能通过获取文件夹及其符号链接信息输出dir

  • 我想要的是这个,其中CNETprojects是符号链接:
    CNET [\\192.168.1.10\CNET]
    elements
    localized
    projects [\\192.168.1.10\CNET\homes\andi\projects]
    render
    

如果我做:

$ dir z:

     Directory of Z:\

    09/12/2023  17:25    <DIR>          .
    08/12/2023  00:16    <DIR>          ..
    09/12/2023  17:25    <SYMLINKD>     CNET [\\192.168.1.10\CNET]
    08/12/2023  01:07    <DIR>          elements
    08/12/2023  02:26    <DIR>          localized
    09/12/2023  17:25    <SYMLINKD>     projects [\\192.168.1.10\CNET\homes\andi\projects]
    08/12/2023  02:26    <DIR>          render
                   0 File(s)              0 bytes
                   7 Dir(s)  346.504.175.616 bytes free

答案1

您可以执行以下操作:

  • 使用for /f循环并用 配置令牌"tokens=4,5,*"
  • 将单引号内的命令插入'dir /AL ^| findstr 192'循环的命令部分。
  • 然后,使用echo %%~A %%~B %%~C显示所需的输出。

该结构允许您处理指定命令的输出,并%%~A, %%~B, and %%~C在每次迭代中表示相关标记以获得适用值的所需输出。

笔记:这是作为批处理脚本运行的格式。

for /f "tokens=4,5,*" %%A in ('dir /AL ^| findstr 192') do (echo %%~A %%~B %%~C)

命令行

笔记:这是从命令行运行的格式。

for /f "tokens=4,5,*" %A in ('dir /AL ^| findstr 192') do (echo %~A %~B %~C)

支持资源

  • 为/F
  • FOR /?
    FOR /F ["options"] %variable IN (`command`) DO command [command-parameters]
    
    
        delims=xxx      - specifies a delimiter set.  This replaces the
                          default delimiter set of space and tab.
        tokens=x,y,m-n  - specifies which tokens from each line are to
                          be passed to the for body for each iteration.
                          This will cause additional variable names to
                          be allocated.  The m-n form is a range,
                          specifying the mth through the nth tokens.  If
                          the last character in the tokens= string is an
                          asterisk, then an additional variable is
                          allocated and receives the remaining text on
                          the line after the last token parsed.
    
    In addition, substitution of FOR variable references has been
    enhanced. You can now use the following optional syntax:
    
    %~I         - expands %I removing any surrounding quotes (")
    %~fI        - expands %I to a fully qualified path name
    %~dI        - expands %I to a drive letter only
    
  • Findstr /?

答案2

该命令的帮助dir显示以下内容:

C:\>dir /?
Displays a list of files and subdirectories in a directory.

DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]
  [/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]] [/W] [/X] [/4]

  [drive:][path][filename]
              Specifies drive, directory, and/or files to list.

  /A          Displays files with specified attributes.
  attributes   D  Directories                R  Read-only files
               H  Hidden files               A  Files ready for archiving
               S  System files               I  Not content indexed files
               L  Reparse Points             O  Offline files
  /B          Uses bare format (no heading information or summary).
.
.
.

使用/b选项仅显示名称(无其他详细信息)并/al切换为显示重新解析点(符号链接和连接点)或/adl

dir /b /al

或者

dir /b /adl

相关内容