"Pegasus (MVP)" <I.can@xxxxxx> wrote in message
> "OldDog" <mikef2691@xxxxxx> wrote in message
> On Sep 9, 9:01 pm, Tom Lavedas <tglba...@xxxxxx> wrote:
>> On Sep 9, 6:37 pm, OldDog <michael.r.felk...@xxxxxx> wrote:
>> > I know this is an old one, but I can't recall how to do it. I want to
>> > read a text file and pick up two variables for my script. The first
>> > item (0) is a file name and the second (1) is a directory.
>> > MPFT.txt looks like this:
>> > input1.txt "\customer1\Sales"
>> > input2.txt "\customer2\Sales"
>> > script looks like this;
>> > Const ForWriting = 2
>> > Const ForReading = 1
>> > 'On Error Resume Next
>> > Set objFSO = CreateObject("Scripting.FileSystemObject")
>> > Set objTextFile = objFSO.OpenTextFile("C:\Scripts\MPFT.txt",
>> > ForReading)
>> > Do Until objTextFile.AtEndOfStream
>> > strFile = Trim(objTextFile.Readline)
>> > If (strFile <> "") Then
>> > 'Check if file exists
>> > ftp_filename = strFile.Item(0)
>> > WScript.Echo ftp_filename
>> > if objFSO.FileExists(strFile.Item(0)) then
>> > wscript.Echo strFile.Item(0) & " exists"
>> > ftp_local_pending = "\\Secretary\Aspen\Data\Reports\" & Year(date) &
>> > strFile.item(1)
>> > ftp_local_archive = "\\Secretary\Aspen\Data\Archives\" & Year(date)
>> > & strFile.item(1)
>> > WScript.Echo ftp_local_pending
>> > WScript.Echo ftp_local_archive
>> I think you want the Split() function. If the two items are separated
>> on a line by as space, then use something like this ...
>> strFile = Trim(objTextFile.Readline)
>> If (strFile <> "") Then
>> aItems = Split(strFile, " ")
>> 'Check if file exists
>> ftp_filename = aItems(0)
>> ' Note the change of syntax. The file input is a string, not an
>> Tom Lavedas
> Thanks, I give it a try. How would I split on a Tab?
> In the line
> aItems = Split(strFile, " ")
> you replace the the bit after the comma with the tab character chr(9).
Or with the pre-defined constant vbTab.
But I am curious - it appears that the filename is guaranteed to contain no
whitespace, while the quotes around the directory path imply that it might
If you have control over the format of the file, why not change it to this
\customer number 3\sales\input file 2.txt
You could then use the available file system objects to extract various
components such as drive, parentfolder, basename, extension, and etc.