Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

How do I read multiple lines from a text file and insert each as the path for a series of multi-layered directories?

$
0
0

I'm trying to set up a VBS script that will set up multiple directories, each a number of folders deep.

I can set up one multi-level directory using the following code:

Option Explicit

Dim objFSO


Const PATH = "c:\THIS\IS\A\TEST"

Set objfso = CreateObject("Scripting.FileSystemObject")

BuildFullPath PATH

Sub BuildFullPath(ByVal FullPath)
If Not objfso.FolderExists(FullPath) Then
BuildFullPath objfso.GetParentFolderName(FullPath)
objfso.CreateFolder FullPath
End If
End Sub

WScript.Quit

And I set up a text file containing all the "PATHS" I want to create.

I also have a DO UNTIL loop that reads each line of the text file. 

Option Explicit

Dim objFSO,objTextFile,strNextLine
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("c:\logs\UNITCASHDIR.txt", ForReading)
Do Until objTextFile.AtEndOfStream

    strNextLine = objTextFile.Readline
    Wscript.Echo strNextLine
Loop

This code just shows what each line is.  I want to take that line and use it as my next "PATH" I'm assuming that I need to replace the constant "PATH" with a variable, so that I can update the line, so I used strPATH.  But what I can't figure out is how to take the line that is read and make it the variable.

Here is what I have put together from the two sets of code above, but I get a syntax error when it gets to line 17:

Option Explicit

Dim objFSO,objTextFile,strNextLine,strPath

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("c:\logs\UNITCASHDIR.txt", ForReading)

Do Until objTextFile.AtEndOfStream

    strNextLine = objTextFile.Readline
    strPath = strNextLine

BuildFullPath strPath

Sub BuildFullPath(ByVal FullPath)
If Not objfso.FolderExists(FullPath) Then
BuildFullPath objfso.GetParentFolderName(FullPath)
objfso.CreateFolder FullPath
End If
End Sub

Loop

WScript.Quit

What should strPATH really "="?? 

Thanks in advance...


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>