dim testLine,LV textLine = "├─1階層目" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) textLine = "│ ├─2階層目" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) textLine = "│ │ ├─3階層目" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) textLine = "│ │ │ ├─4階層目" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) textLine = "│ │ │ └─test" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) textLine = "│ │ │ ├─a" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) textLine = "│ │ │ └─b" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) textLine = "│ │ └─test" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) textLine = "│ │ ├─a" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) textLine = "│ │ └─b" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) textLine = "│ └─test" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) textLine = "│ ├─a" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) textLine = "│ └─b" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) textLine = "└─他のフォルダ" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) textLine = " ├─test" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) textLine = " │ ├─a" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) textLine = " │ │ └─aa" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) textLine = " │ └─b" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) textLine = " │ └─bb" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) textLine = " └─test2" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) textLine = " ├─a" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) textLine = " │ └─aa" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) textLine = " └─b" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) textLine = " └─bb" : ot = textLIne & "_gettarLV=" & gettarLV(textLIne) 'VBAならstrconvでunicodeを変換できるけど、VBSじゃできないらしい function gettarLV(uniTextLine) dim textLine : textLine = replace(uniTextLine," "," ")'半角文字が2バイトになるのを回避 dim p : p = instr(textLine,"─") '罫線のPositionをバイトで返す dim mFlag : mFlag = (p+1) mod 4 dim tarLV : tarLV = (p+1)/4 if mFlag = 0 then dim oFLag: oFlag = 1 dim k for k = 1 to mFlag -1 if strconv(midB(textLine,4*k -1,2),vbFromUnicode) <> " " then 'スペース2つ oFlag = 0 exit for end if next tarLV = 0 if oFlag = 1 then tarLV = (p+1)/4 end if gettarLV = tarLV dim txt txt = txt & "textLine = " & textLine & chr(10) txt = txt & "p = " & p & " tarLV= " & tarLV msgbox txt end function ' 正規表現チェック関数 Function gettarLV2( textLine ) ' 正規表現のマッチングパターン pattern1 = "^..─" pattern2 = "^.. ..─" pattern3 = "^.. .. ..─" pattern4 = "^.. .. .. ..─" Set regEx = CreateObject("VBScript.RegExp") tarLV = 0 if tarLV = 0 then regEx.Pattern = pattern4 : If(regEx.Test(leftB(textLine,4*4)))Then tarLV = 4 if tarLV = 0 then regEx.Pattern = pattern3 : If(regEx.Test(leftB(textLine,4*3)))Then tarLV = 3 if tarLV = 0 then regEx.Pattern = pattern2 : If(regEx.Test(leftB(textLine,4*2)))Then tarLV = 2 if tarLV = 0 then regEx.Pattern = pattern1 : If(regEx.Test(leftB(textLine,4*1)))Then tarLV = 1 gettarLV = tarLV End Function function gettarLV(textLine) dim p : p = instrB(textLine,"─") '罫線のPositionをバイトで返す dim mFlag : mFlag = (p+1) mod 4 dim tarLV : tarLV = (p+1)/4 if mFlag = 0 then dim oFLag: oFlag = 1 dim k for k = 1 to mFlag -1 if midB(textLine,4*k -1,2) <> " " then 'スペース2つ oFlag = 0 exit for end if next tarLV = 0 if oFlag = 1 then tarLV = (p+1)/4 end if gettarLV = tarLV dim txt txt = txt & "textLine = " & textLine & chr(10) txt = txt & "p = " & p & " tarLV= " & tarLV msgbox txt end function