Reputation: 1
Let me first start off by saying I'm not experienced, but I know a little bit. I need some help with VBS. I'm trying to create a script that will open a text file, search for a specific string within the file and then cut part string down and use it as a variable. Let me explain why. I have a text file that has a network path in it. The path will be different from person to person, hence why I need pull this as a value.
<setting name="ConfigPathV4" serial="String">
<value>\\ServerName\Foldername</value>
The path I need to pull out of the string is
\\Servername\Foldername
Once I have that path, I need to be able to copy certain file types from the path (XLL,DLL,DNA) to a local folder.
The catch is, I might need to reference this path later in the script as I'm doing way more than just this. Is this even possible?
Upvotes: 0
Views: 702
Reputation: 489
To read your text file contents
Set objFSO = createObject("scripting.FileSystemObject")
ObjFile = objFSO.OpenTextFile(FilePath)
StrText= objFile.ReadAll
ObjFile.close
Set objFile= nothing
To extract the path value
Set objXML = createObject("msxml2.domdocument")
objXML.LoadXML strText
StrExtractedPath=ObjXML.SelectSingleNode("value").NodeValue
To copy files from the path
DestFile = "MyFile"
DestPath = "pathToTheDestFile"
SrcFile = "FileToCopy"
ObjFSO.MoveFile(DestPath& DestFile, StrExtractedPath & SrcFile) 'This statement can move most of the file types
Garbage collection
Set objFSO = nothing
Set objXML = nothing
Have typed this answer on phone, so there might be a debugging and syntax correction required
Upvotes: 1