I want to do a search with the 7z list command in powershell for certain folder names
Here is a batch file solution. Feel free to convert it to PowerShell (it shouldn't be too difficult).
@echo off
setlocal enabledelayedexpansion
for /F "tokens=6" %%d in ('c:\apps\7-zip\7z l -ba test.7z ^| findstr /c:"D...."') do (
echo %%d
)
endlocal
The important bits are the -be flag on the 7z command (which is an undocument switch). This changes the list format to something that looks like:
F:\test>c:\apps\7-zip\7z l -ba test.7z
2019-11-19 21:13:50 D.... 0 0 test
2020-04-02 10:31:49 D.... 0 0 test\colors
2020-04-06 23:32:17 D.... 0 0 test\colors\colors
2020-04-16 21:20:02 D.... 0 0 test\sub 1
2021-12-26 19:26:10 D.... 0 0 test\sub 1\test.bat
2020-04-16 21:20:00 D.... 0 0 test\sub 2
2021-04-30 19:37:15 D.... 0 0 test\txt
2021-01-27 18:40:08 ....A 0 0 test\1.mp4
2021-01-02 16:07:34 ....A 0 0 test\2.mp4
2021-01-02 16:07:34 ....A 0 0 test\3.mp4
2020-04-16 21:07:16 ....A 0 0 test\Apr
2020-04-06 23:32:29 ....A 0 0 test\colors\colors\blue.txt
2020-04-06 23:32:29 ....A 0 0 test\colors\colors\green.txt
2020-04-06 23:32:29 ....A 0 0 test\colors\colors\red.txt
2020-04-06 23:44:29 ....A 0 0 test\colors\colors\sky blue pink.txt
etc ...
The output lists the directories first and then the files.
Directories contain the string D.... in token (column) 3 so you can filter on this. The directory names are in token (column) 6.
Once you have the directory names you can then filter again to find the name you want.
Example output:
F:\test>test
test
test\colors
test\colors\colors
test\sub
test\sub
test\sub
test\txt
F:\test>
Further Reading