|
server
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Parse txt file and output to cmd file
64-bit world. In our build scripts we echo the computer name to a txt file then need to read the name. Based on the name we import settings into our unattened.txt file. I have goten it to read the first 5 letters of the name but when I do a strContents=objTextStream.skip(5) It doesn't return anything. Example of working READ: Const FOR_READING = 1 Const FOR_Writing = 2 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFiles=objFSO.GetFile("C:\$oem$\Name.txt") Set objTextStream = objFSO.OpenTextFile ("c:\$oem$\Name.txt", FOR_READING) strContents = objTextStream.Read(5) WScript.Echo"set site "& strContents objTextStream.Close Set objFSO = CreateObject ("Scripting.fileSystemObject") Set objFile = objFSO.OpenTextFile ("C:\$oem$\env.cmd", FOR_WRITING , True) objFile.Write "set site "& strContents objFile.WriteBlankLines (2) Example NOT working Skip: Const FOR_READING = 1 Const FOR_APPENDING = 8 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFiles=objFSO.GetFile("C:\$oem$\Name.txt") Set objTextStream = objFSO.OpenTextFile ("c:\$oem$\Name.txt", FOR_READING) strContents=objTextStream.skip(5) WScript.Echo"set dom "& strContents objTextStream.Close Set objFSO = CreateObject ("Scripting.fileSystemObject") Set objFile = objFSO.OpenTextFile ("C:\$oem$\env.cmd", FOR_APPENDING , True) objFile.Write "set dom "& strContents objFile.WriteBlankLines (2) I found the problem with this script.
The Skip worked but I didn't tell it to read again. I added this objTextStream.skip(5) strContents=objTextStream.Read(1) By adding this I was able to pull the 7th character of the computer name and drop it in a text file. Show quote "Michael" wrote: > I am working on updating some of our out dated unattened installs for the > 64-bit world. > > In our build scripts we echo the computer name to a txt file then need to > read the name. Based on the name we import settings into our unattened.txt > file. > > I have goten it to read the first 5 letters of the name but when I do a > strContents=objTextStream.skip(5) > It doesn't return anything. > > Example of working READ: > Const FOR_READING = 1 > Const FOR_Writing = 2 > Set objFSO = CreateObject("Scripting.FileSystemObject") > Set objFiles=objFSO.GetFile("C:\$oem$\Name.txt") > Set objTextStream = objFSO.OpenTextFile ("c:\$oem$\Name.txt", FOR_READING) > strContents = objTextStream.Read(5) > WScript.Echo"set site "& strContents > objTextStream.Close > Set objFSO = CreateObject ("Scripting.fileSystemObject") > Set objFile = objFSO.OpenTextFile ("C:\$oem$\env.cmd", FOR_WRITING , True) > objFile.Write "set site "& strContents > objFile.WriteBlankLines (2) > > Example NOT working Skip: > > Const FOR_READING = 1 > Const FOR_APPENDING = 8 > Set objFSO = CreateObject("Scripting.FileSystemObject") > Set objFiles=objFSO.GetFile("C:\$oem$\Name.txt") > Set objTextStream = objFSO.OpenTextFile ("c:\$oem$\Name.txt", FOR_READING) > strContents=objTextStream.skip(5) > WScript.Echo"set dom "& strContents > objTextStream.Close > Set objFSO = CreateObject ("Scripting.fileSystemObject") > Set objFile = objFSO.OpenTextFile ("C:\$oem$\env.cmd", FOR_APPENDING , True) > objFile.Write "set dom "& strContents > objFile.WriteBlankLines (2) Personally, I would find it simpler to read in the entire line from the file
and parse out the result. For example, if the name is only two characters long your script will choke without knowing exactly why. If you read it in first its length can be tested. /Al Show quote "Michael" <Mich***@discussions.microsoft.com> wrote in message news:F166F5FC-5378-4BE9-9F57-A83D5A19C865@microsoft.com... >I found the problem with this script. > > The Skip worked but I didn't tell it to read again. I added this > > objTextStream.skip(5) > strContents=objTextStream.Read(1) > > By adding this I was able to pull the 7th character of the computer name > and > drop it in a text file. > > > "Michael" wrote: > >> I am working on updating some of our out dated unattened installs for the >> 64-bit world. >> >> In our build scripts we echo the computer name to a txt file then need to >> read the name. Based on the name we import settings into our >> unattened.txt >> file. >> >> I have goten it to read the first 5 letters of the name but when I do a >> strContents=objTextStream.skip(5) >> It doesn't return anything. >> >> Example of working READ: >> Const FOR_READING = 1 >> Const FOR_Writing = 2 >> Set objFSO = CreateObject("Scripting.FileSystemObject") >> Set objFiles=objFSO.GetFile("C:\$oem$\Name.txt") >> Set objTextStream = objFSO.OpenTextFile ("c:\$oem$\Name.txt", >> FOR_READING) >> strContents = objTextStream.Read(5) >> WScript.Echo"set site "& strContents >> objTextStream.Close >> Set objFSO = CreateObject ("Scripting.fileSystemObject") >> Set objFile = objFSO.OpenTextFile ("C:\$oem$\env.cmd", FOR_WRITING , >> True) >> objFile.Write "set site "& strContents >> objFile.WriteBlankLines (2) >> >> Example NOT working Skip: >> >> Const FOR_READING = 1 >> Const FOR_APPENDING = 8 >> Set objFSO = CreateObject("Scripting.FileSystemObject") >> Set objFiles=objFSO.GetFile("C:\$oem$\Name.txt") >> Set objTextStream = objFSO.OpenTextFile ("c:\$oem$\Name.txt", >> FOR_READING) >> strContents=objTextStream.skip(5) >> WScript.Echo"set dom "& strContents >> objTextStream.Close >> Set objFSO = CreateObject ("Scripting.fileSystemObject") >> Set objFile = objFSO.OpenTextFile ("C:\$oem$\env.cmd", FOR_APPENDING , >> True) >> objFile.Write "set dom "& strContents >> objFile.WriteBlankLines (2) |
|||||||||||||||||||||||