Parsing Windows TREE Command Output

Q

Regex for parse output of Windows TREE command. For example:

Folder PATH listing
Volume serial number is 8704-028C
C:
+---BIOS
|   \---E0CN23WW
|           E0CN23WW.exe
|           
+---driveri
|       0rww03af.exe
|       2tl502af.exe
|       2tl602af.exe
|       365.10-notebook-win10-64bit-international-whql (1).exe
|       bob501af.exe
|       e0cn23ww_ia32.exe
|       
+---drivers
|   +---Bluetooth Driver
|   |   |   0x0402.ini
|   |   |   0x0403.ini
|   |   |   
|   |   +---BT_Driver
|   |   |   \---Win10X64
|   |   |           bthvirtual.cat
|   |   |           bthvirtual.inf
|   |   |           rtka2dp.cat
|   |   |           RtkA2dp.inf
|   |   |           RtkHfp.sys
|   |   |           
|   |   \---Release notes
|   |           readme.txt
|   |           Release_RTKBluetoothE.txt
|   |           
|   +---Camera Driver (Gennis, Realtek)
|   |   |   DeDrvLdr.ini
|   |   |   Install.exe
|   |   |   
|   |   +---10.0.10120.11122
|   |   |   |   data1.cab
|   |   |   |   data1.hdr
|   |   |   |   data2.cab
And so on ...

I need way to create folder and file structure from output like that.

✍: Excrucio

A

Hi Excrucio, You can try the following logic:

1. Loop through the output one line at a time
2. Use ^.*[+\]---(.*)$ to match for a folder name
3. Do what needed for the folder
3. Use ^(?!.*[+\]---).*\| +(.+)$ to match for a file name
4. Do whatever needed for the file

2016-06-23, 788👍, 0💬