Следующее, вероятно, не совсем то, что вам нужно, но должно помочь вам в этом:
def parsePathname: split("\\") | {path: .[0:length-1], file: .[-1]};
# skip over lines that only specify directories
def pathnames:
foreach inputs as $x (null;
if . == null
then if ($x|length) == 0 then 0 else . end
else .+1
end;
select(. and . > 0)|$x)
| parsePathname ;
reduce pathnames as $pn ({};
getpath($pn.path + ["children"]) as $children
| setpath($pn.path + ["children"]; $children + [$pn.file]) )
Вывод
Когда ваш список обрезан из ориентировочных строк, выполните следующую команду:
jq -R -n -f dirtree.jq dirtree.txt
производит:
{
"C:": {
"Program Files": {
"children": [
"desktop.ini"
],
"7-Zip": {
"children": [
"7-zip.chm",
"7-zip.dll",
"7-zip32.dll",
"7z.dll",
"7z.exe",
"7z.sfx",
"7zCon.sfx",
"7zFM.exe",
"7zG.exe",
"descript.ion"
]
},
"WindowsPowerShell": {
"Modules": {
"PSReadline": {
"1.2": {
"children": [
"Microsoft.PowerShell.PSReadline.dll",
"PSReadline.psd1",
"PSReadline.psm1"
],
"en": {
"children": [
"Microsoft.PowerShell.PSReadline.Resources.dll"
]
}
}
}
}
}
}
}
}