Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replace file script 2

Status
Not open for further replies.

moogeboo

MIS
Aug 7, 2003
28
US
hi,

i'm pretty new to vb scripting, and i wanted to write a script that seems pretty simple, but am unsure as to how to proceed. what i want to do is:

check to see if a certain file exist (c:\program files\file.txt)
replace it with an updated file @ (H:\newfiles\updatedfile.txt)

that's all. seems pretty easy, but...am not sure as how to go about this...any ideas would be appreciated!

thanks!
 
Try something like this:
Code:
Set fso=CreateObject("Scripting.FileSystemObject")
old="c:\program files\file.txt"
new="H:\newfiles\updatedfile.txt"
If fso.FileExists(old) Then
  fso.CopyFile new,old,True
  WScript.Echo old & " updated by " & new
Else
  WScript.Echo old & " NOT FOUND"
End If


Hope This Help
PH.
 
moogeboo, thanks for sharing.
Can you please tell the members if this thread is successfully closed ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Hello PHV,

As far as I'm concerned, this thread is successfully closed except "new" be replaced by "nouveau"---is it a keyword?---or something.

Should not anticipate too much the other party for a feedback in this biz, that's too much frustration to bear day-in-day-out. Keep the morale up and congratulations for the top ranking forum-wide.

regards - tsuji
 
Yes, [tt]New[/tt] is indeed a keyword. You use it to instantiate a class.

Code:
Class Crud
  :
End Class

Dim objCrud

Set objCrud = New Crud
 
dilettante,

Yes, "new" of course is a keyword that's why it would error out if do nothing about. I was just trying to ask and badly put whether "nouveau" were---most probably not---in French version of vbs engine! Just ask in passing.

regards - tsuji
 
Hello all,

Out of no reason, I suddenly want to place a footnote on the small issue proper to my note above. This is at the fringe of the vbscripting practice but more common in dbase related programming, viz, How to deal with the variable or function/sub names being by chance or by design unfortunately a reserved word or with "forbidden" characters? Rule : Enclose them in square brackets.

This is a demonstration.
Code:
dim [new], [_],[%]
[new]=1 : [_]=2 : [%]=3
wscript.echo [new]+[_]+[%]
regards - tsuji
 
can i jump in on this thread? with a question..which will get a response from me,,,especially if no one answers ;-)

i want vbscript to enterpret a string=value and actually update a variable with the said value.

So if i started a vbscript with:

d:\test.vbs sLocation=BRA

in the test.vbs I DONT want to do the select case



Dim sLocation
sLocation = regread("HKLM\FSC\HomeLocation")

'get args and override something
For Each aArg In ObjArgs
sKey = Mid(InStr(aArg, "="), ...)
sValue = Mid(gets the RHS of the =)
Select Case sKey
Case "sLocation"
sLocation = sValue
End Select
Next

i know its not in the spirit of this thread,,
 
Hello mrmovie,

I'm not clever enough. But would do retrieve the script and parse it with string functions helped with array functions and eval-type functionality.
Code:
sScript=createobject("scripting.filesystemobject").opentextfile(wscript.scriptfullname).readall)
regards - tsuji
 
Try something like this:
For Each aArg In ObjArgs
If InStr(aArg, "=") > 0 Then Execute aArg
Next

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
what can i say, a moment of truth.
im not being a pr@ck but i have made a number of posts in this forum over last couple of years and was beginning to loose faith!!! dont get me wrong ive picked up lots of tips just from reading other threads,,,cheers everyone.

but, in this case the big up has to go to PHV, class post, its so simple and thats why i never would have got it ;-)

doesnt look like much to the casual observer but will make my life so much easier.

thanks again
von moyla
 
Hello again,

Well, PHV enjoy your star.

But, I have my word to say. I would say this. What if the argument sLocation being any other thing, sLokation. The reason I propose to identify sLocation being the exact "name" of the variable is to assure you do not execute a thing other than under your exact control. Meaning, if Option explicit is in the script, you'd get runtime error. If no option explicit, you have another deliquant variable sLokation, whereas sLocation has not been changed. That's all I have to say.

regards - tsuji
 
im in agreement there are knockon effects of this flexibility, i guess its up to me to decide if i can minimize the risks involved and are happy to accept them and be aware of them before implementing the possiblities.
cheers all
 
Code:
test.vbs nRet=createobject("wscript.shell").run(ILoveYou.vbs)
enjoy - tsuji
 
Hello mrmovie,

But seriously, I would consider named arguments.
Code:
test.vbs /sLocation:"BRA"
with within the script for sLocation or any other variable to this effect.
Code:
if wscript.arguments.named.exists("sLocation")
    sLocation=wscript.arguments.named.item("sLocation")
end if
You've reasons to be disillusion. But, that is not the reason.

Cheer up - tsuji
 
ok, have a star, didnt know you could do named arguments
cheers mr movie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top