加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows-7 – 列出具有指定名称的所有子目录

发布时间:2020-12-13 22:32:39 所属栏目:Windows 来源:网络整理
导读:我试图获得所有子目录(递归)的路径列表,这些路径具有一些指定的名称,例如“斌”.问题是如果当前目录包含该名称的子目录,则DIR命令将仅在该子目录中执行,忽略其他子目录. 例: C:DEVELOPMENTRESEARCHverMicrosoft Windows [Version 6.1.7601]C:DEVELOPMENT
我试图获得所有子目录(递归)的路径列表,这些路径具有一些指定的名称,例如“斌”.问题是如果当前目录包含该名称的子目录,则DIR命令将仅在该子目录中执行,忽略其他子目录.

例:

C:DEVELOPMENTRESEARCH>ver

Microsoft Windows [Version 6.1.7601]

C:DEVELOPMENTRESEARCH>dir *bin* /ad /s /b
C:DEVELOPMENTRESEARCHbin
C:DEVELOPMENTRESEARCHApache2bin
C:DEVELOPMENTRESEARCHApachebin
C:DEVELOPMENTRESEARCHApachebin1
C:DEVELOPMENTRESEARCHC#ConsoleAppsMiscTestsbin

C:DEVELOPMENTRESEARCH>dir bin* /ad /s /b
C:DEVELOPMENTRESEARCHbin
C:DEVELOPMENTRESEARCHApachebin
C:DEVELOPMENTRESEARCHApachebin1
C:DEVELOPMENTRESEARCHC#ConsoleAppsMiscTestsbin

C:DEVELOPMENTRESEARCH>dir bin /ad /s /b
C:DEVELOPMENTRESEARCHbintest    

C:DEVELOPMENTRESEARCH>rmdir bin /s /q

C:DEVELOPMENTRESEARCH>dir bin /ad /s /b
C:DEVELOPMENTRESEARCHApachebin
C:DEVELOPMENTRESEARCHC#ConsoleAppsMiscTestsbin

C:DEVELOPMENTRESEARCH>

dir * bin * / ad / s / b输出名称中包含bin的所有子目录.这个输出没问题.与dir bin * / ad / s / b相同,它输出名称以bin开头的所有子目录.但是dir bin / ad / s / b仅输出当前目录中具有名称bin的第一个子节点的内容.期望的输出是:

C:DEVELOPMENTRESEARCHbin
C:DEVELOPMENTRESEARCHApachebin
C:DEVELOPMENTRESEARCHC#ConsoleAppsMiscTestsbin

我怎样才能做到这一点?

注意:如果当前目录不包含bin子,则输出是预期的. (我删除了bin子来显示这个)

解决方法

如果当前目录包含bin子目录,则使用标准DOS命令很困难.我认为你有三个基本选择:

# Option 1: FOR and check directory existance (modified from MBu's answer - the
# original answer just appended 'bin' to all directories whether it existed or not)
# (replace the 'echo %A' with your desired action)
for /r /d %A in (bin) do if exist %ANUL echo %A

# Option 2: PowerShell (second item is if you need to verify it is a directory)
Get-ChildItem -filter bin -recurse
Get-ChildItem -filter bin -recurse |? { $_.Attributes -match 'Directory' }

# Option 3: Use UNIX/Cygwin find.exe (not to be confused in DOS find)
# (you can locate on the net,such as GNU Utilities for Win32)
find.exe . -name bin
find.exe . -name bin -type d

> DOS Testing if drive or directory exists
> Cygwin
> GNU Utilities for Win32

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读