|
Answer» Hi, i am looking for a batchfile that does the following:
i have a config file that has the following lines:
name001=pc0001 ~ name088=pc0029 name089=pc0199
Now i want to be able when running the batch a line wil be added to the config file with name... with one number HIGHER than the last line + the current pc number. So when running this batch from pc0215 the following line should be added:
name090=pc0215
I know %computername% can be used to print the pc number.
Thanx in advanceare the 4 characters 'name' an example, or are they what actually appear?
Whether the answer is yes or no, is the part before the number always 4 characters long?
vbscript Code: [Select]Set objFS=CreateObject("Scripting.FileSystemObject") Set WshNetwork = WScript.CreateObject("WScript.Network") strComputerName=WshNetwork.ComputerName Set objArgs = WScript.Arguments strConfigFile = objArgs(0) strTemp = "temp" Set objTemp = objfs.CreateTextFile(strTemp,True) Set objFile = objFS.OpenTextFile(strConfigFile) data= Split(objFile.ReadAll,vbCrLf) s = Split( data( UBound(data) - 1 ) , "=") s1 = Replace(s(0), "name","") length = Len(s1) s1=s1+1 strNewValue = "name" & Pad(s1,length) & "=" & strComputerName data( UBound(data) ) = strNewValue
For i=LBound(data) To UBound(data) objTemp.Write(data(i) & vbCrLf ) Next
objTemp.Close objFile.Close
If objFS.FileExists(strConfigFile) Then objFS.DeleteFile(strConfigFile) objFS.MoveFile strTemp,strConfigFile End If
Function Pad(input, howmany) 'Pad leading zeroes to a string till length of howmany If Len(input) <= howmany Then Do Until Len(input) = howmany input = "0" & input Loop Pad = input End If End Function
usage Code: [Select]c:\test> cscript //nologo myscript.vbs configfile Thanks a *censored* bunch, Ghostdog, I was right in the MIDDLE of a dinky little batch! Nothing like having your motivation taken away to make you feel good. You did see the "from batch" in the title?
Anyhow, ns1207, if you still want a batch solution, say so and also answer my question above and I may continue...
Quote from: Salmon Trout on December 09, 2009, 05:08:33 AM Thanks a <censored> bunch, Ghostdog, I was right in the middle of a dinky little batch! Nothing like having your motivation taken away to make you feel good. You did see the "from batch" in the title? Anyhow, ns1207, if you still want a batch solution, say so and also answer my question above and I may continue...
actually, the solution to your problem is very simple, just ignore my posts, because its intended audience is originally for the OP and not anybody else. And please do post your batch version, nobody has the any reasons to stop you, right?
Quote from: Salmon Trout link You did see the "from batch" in the title?
sometimes title and actual post contents are not synonymous. put the vbs command in a file, and call it a batch file. And that's a batch !You censored "*censored*"? Quote from: Salmon Trout on December 09, 2009, 07:43:01 AMYou censored "*censored*"?
probably the forum. seems to censor strange things when the quote button is used.Anyhow, the reason I became demotivated was because Ghostdog's solution is so much better. I WONDER if there is an audience for Autoit scripts? Quote from: Salmon Trout on December 09, 2009, 07:43:01 AMYou censored "<censored>"?
when i click reply with quote, it shows me "censored". I did not do anything though.You must have CENSORING set in your forum preferences, I think.
|