Команда для перечисления всех файлов и filesizes, содержащихся в папках, которые соответствуют определенному имени?

Я хотел бы распечатать все имена файлов и размеры файлов, которые находятся в любой папке, которая соответствует «alpha».

Я понимаюdir /s, что буду печатать все имена файлов и размеры всей директории и подкаталогов рекурсивно, но не знаю, как написать команду, чтобы только отобразить содержимое папок, которые соответствуют определенной строке (в моем случае alpha ) в их пути к файлу.

например, если это мой каталог:

C:Usersraigovind93Documents

I would like to print all file names and sizes of files that are located in any folder that matches "alpha".

I understand dir /s will print all file names and sizes of the entire directory and sub directories recursively, but don't know how write a command to only display contents of folders which match a specific string (in my case alpha) in their file path.

for example if this is my directory:

C:Usersraigovind93Documents1alphadoc1.txt
C:Usersraigovind93Documents211alphadoc2.pptx
C:Usersraigovind93Documents211alphaappledoc3.xslx

I would like to print:

doc1.txt 20020 bytes
doc2.pptx 102002 bytes
doc3.xslx 289 bytes

And for clarity sake, if you can show both an answer that shows folders along with file names (to verify correctness of the command) and one without folders, that will be super helpful!

alphadoc1.txt
C:Usersraigovind93Documents

I would like to print all file names and sizes of files that are located in any folder that matches "alpha".

I understand dir /s will print all file names and sizes of the entire directory and sub directories recursively, but don't know how write a command to only display contents of folders which match a specific string (in my case alpha) in their file path.

for example if this is my directory:

C:Usersraigovind93Documents1alphadoc1.txt
C:Usersraigovind93Documents211alphadoc2.pptx
C:Usersraigovind93Documents211alphaappledoc3.xslx

I would like to print:

doc1.txt 20020 bytes
doc2.pptx 102002 bytes
doc3.xslx 289 bytes

And for clarity sake, if you can show both an answer that shows folders along with file names (to verify correctness of the command) and one without folders, that will be super helpful!

I would like to print all file names and sizes of files that are located in any folder that matches "alpha".

I understand dir /s will print all file names and sizes of the entire directory and sub directories recursively, but don't know how write a command to only display contents of folders which match a specific string (in my case alpha) in their file path.

for example if this is my directory:

C:Usersraigovind93Documents1alphadoc1.txt
C:Usersraigovind93Documents211alphadoc2.pptx
C:Usersraigovind93Documents211alphaappledoc3.xslx

I would like to print:

doc1.txt 20020 bytes
doc2.pptx 102002 bytes
doc3.xslx 289 bytes

And for clarity sake, if you can show both an answer that shows folders along with file names (to verify correctness of the command) and one without folders, that will be super helpful!

alphadoc2.pptx
C:Usersraigovind93Documents

I would like to print all file names and sizes of files that are located in any folder that matches "alpha".

I understand dir /s will print all file names and sizes of the entire directory and sub directories recursively, but don't know how write a command to only display contents of folders which match a specific string (in my case alpha) in their file path.

for example if this is my directory:

C:Usersraigovind93Documents1alphadoc1.txt
C:Usersraigovind93Documents211alphadoc2.pptx
C:Usersraigovind93Documents211alphaappledoc3.xslx

I would like to print:

doc1.txt 20020 bytes
doc2.pptx 102002 bytes
doc3.xslx 289 bytes

And for clarity sake, if you can show both an answer that shows folders along with file names (to verify correctness of the command) and one without folders, that will be super helpful!

I would like to print all file names and sizes of files that are located in any folder that matches "alpha".

I understand dir /s will print all file names and sizes of the entire directory and sub directories recursively, but don't know how write a command to only display contents of folders which match a specific string (in my case alpha) in their file path.

for example if this is my directory:

C:Usersraigovind93Documents1alphadoc1.txt
C:Usersraigovind93Documents211alphadoc2.pptx
C:Usersraigovind93Documents211alphaappledoc3.xslx

I would like to print:

doc1.txt 20020 bytes
doc2.pptx 102002 bytes
doc3.xslx 289 bytes

And for clarity sake, if you can show both an answer that shows folders along with file names (to verify correctness of the command) and one without folders, that will be super helpful!

alphaappledoc3.xslx

Я хотел бы напечатать:

doc1.txt 20020 bytes
doc2.pptx 102002 bytes
doc3.xslx 289 bytes

И для ясности, если вы можете показать как ответ, который показывает папки вместе с именами файлов (для проверки правильности команды), так и один без папок, это будет очень полезно!

3 ответа

  1. Попробуйте использовать

    dir /s |find /I "\alpha\"
    

    Вы можете использовать ‘find’ с трубой на других командах тоже.

  2. в командной строке:

    for /r %a in (*) do @echo %a %~za bytes|find /i "\alpha\"
    

    для использования в batchfiles удваивайте процентные знаки:

    for /r %%a in (*) do @echo %%a %%~za bytes|find /i "\alpha\"
    

    for /?Подробнее см.

  3. Возвращает dir /B /S /A:-Dвсе файлы ( /A:-D) в текущем рабочем каталоге рекурсивно (/S) в виде голого списка (/B), затем передает |результат в find /I "\alpha\"фильтр для элементов, которые содержат \alpha\в своих путях регистр-нечувствительно (/I); затем анализирует его вывод for /Fциклом:

    for /F "eol=| delims=" %F in ('dir /B /S /A:-D ^| find /I "\alpha\"') do echo %~nxF %~zF bytes
    

    Чтобы включить полные пути в возвращаемые элементы, замените %~nxFна %~fF.

    Не забудьте удвоить %знаки, чтобы использовать эту командную строку в пакетном файле.