Hi,
I am trying to split a text file, which contains a list of servers alphabetically, into three. So far, thanks to "Pegasus [MVP]" I have the following and still stuck here. i think i am approaching this from the wrong angle, any thoughts?
My task is as follows:
Servers.txt file to split evenly into three text files, retaining the alphabetical order of the servers.
sFolder = "c:\dev1"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sFolder)
If oFSO.FolderExists(sFolder & "\Temp") _
Then oFSO.DeleteFolder sFolder & "\Temp"
oFSO.CreateFolder(oFolder.Path & "\Temp")
For Each oFile In oFolder.Files
sName1 = oFile.ParentFolder & "\Temp\" & oFile.Name
sName2 = oFile.ParentFolder & "\Temp\" _
& Left(oFile.Name, Len(oFile.Name) - 5) & "2.txt"
Set oTextFile = oFSO.OpenTextFile(oFile, 1)
Set oOut1 = oFSO.CreateTextFile(sName1)
Set oOut2 = oFSO.CreateTextFile(sName2)
sText = oTextFile.Readall
aText = Split(sText, VbCrLf)
For i = 0 To UBound(aText) \ 3
oOut1.WriteLine aText(i)
Next
For i = UBound(aText) \ 3 + 1 To UBound(aText)
oOut2.WriteLine aText(i)
Next
oTextFile.Close
oOut1.Close
oOut2.Close
Next
For Each oFile In oFolder.Files
oFSO.DeleteFile oFile
Next
Set oTemp = oFSO.GetFolder(oFolder.Path & "\Temp")
For Each oFile In oTemp.Files
oFSO.MoveFile oFile, oFolder.Path & "\" & oFile.Name
Next
Bookmarks