Advertisement
steed1998

mkdir_from_tree_v2.vbs

Oct 28th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. OptiOn Explicit
  2. Dim oFSO, oSource, oRegEx1, oRegEx2, oIsBranch, strLine, Lcnt, ArrCD(), strChr, strPre, _
  3. i, spcnt, Depth, strBpath, oErrOut, strFPath, ErrStr
  4. Set oFSO = WScript.Createobject("Scripting.FileSystemobject")
  5. Set oSource = oFSO.OpenTextFile(Wscript.Arguments(0), 1)
  6. Set oRegEx1 = Createobject("VBScript.RegExp")
  7. oRegEx1.pattern = "├|└"
  8. oRegEx1.Global = True
  9. Set oRegEx2 = Createobject("VBScript.RegExp")
  10. oRegEx2.pattern = "^[\s|│]+\s+"
  11. oRegEx2.Global = True
  12.  
  13. Lcnt= 1
  14. Do Until oSource.AtEndOfStream
  15.     strLine = oSource.ReadLine
  16.     If Lcnt = 3 Then
  17.         Redim ArrCD(0)
  18.         ArrCD(0) = strLine
  19.     ElseIf Lcnt > 3 Then
  20.         Set oIsBranch = oRegEx1.execute(strLine)
  21.         If oIsBranch.count > 0  Then
  22.             Call MkDir(oIsBranch.Item(0).Value)
  23.         elseIf Len(oRegEx2.replace(strLine,"")) >0 Then
  24.             Call MkFile()
  25.         End If
  26.     End If
  27.     Lcnt = Lcnt+1
  28. Loop
  29. oSource.Close
  30. Set oSource = Nothing
  31. Set oFSO = Nothing
  32. Set oIsBranch = Nothing
  33. Set oRegEx1 = Nothing
  34. Set oRegEx2 = Nothing
  35. MsgBox("完了しました。")
  36.  
  37. Sub MkDir(strChr)
  38. strPre=MidB(strLine, 1, InStrB(strLine,strChr))
  39. spcnt=0
  40. For i = 1 To Len(strPre)
  41.     If Mid(strPre, i, 1) = " " Then spcnt = spcnt+1
  42. Next
  43. Depth = (InStrB(strLine,strChr)-spcnt)\4+1
  44. Redim Preserve ArrCD(Depth)
  45. ArrCD(Depth) = MidB(strLine, InStrB(strLine,strChr)+4)
  46. strBpath=Join(ArrCD,"\")
  47. On Error Resume Next
  48. oFSO.CreateFolder(strBpath)
  49. If Err.Number > 0 Then
  50.     Call Errwrite(strBpath)
  51. End If
  52. On Error goto 0
  53. End Sub
  54.  
  55. Sub MkFile()
  56. If strBpath="" Then
  57.     strFPath =ArrCD(0) & "\" & oRegEx2.replace(strLine,"") & ".txt"
  58. else
  59.     strFPath =strBpath & "\" & oRegEx2.replace(strLine,"") & ".txt"
  60. End If
  61. On Error Resume Next
  62. oFSO.CreateTextFile(strFPath)
  63. If Err.Number > 0 Then
  64.     Call Errwrite(strFPath)
  65. End If
  66. On Error goto 0
  67. End Sub
  68.  
  69. Sub ErrWrite(ErrStr)
  70. Set oErrOut = oFSO.OpenTextFile(oFSO.getParentFolderName(WScript.ScriptFullName) & "\Errlist.txt", 8, True)
  71. oErrOut.WriteLine ErrStr
  72. oErrOut.Close
  73. Set oErrOut = Nothing
  74. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement