Hi,

Can anybody give me a hand?

I need to write a VBSCript that moves a file from the INSTALLDIR to the users mydocuments folder that resides under their homedrive.

Basically the package I've create installs a config file to C:\Program Files\PGDS-US\PGDS Broadcast Ticker which is the INSTALLDIR. Within this directory is a file entitled "PGDS-NET-CLIENT.cfg".

I want my VBScript to move this file from the INSTALLDIR location to the mydocuments folder which is re-directed to; O:\Data\My Documents.

Can anybody give me a hand with creating a script? I've already created the sample one below but it doesn't appear to work;

Option Explicit
Dim oFSO, oShell, sDirectory
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")
sDirectory = oShell.SpecialFolders("MyDocuments")
If not oFSO.FileExists("C:\Program Files\PGDS-US\PGDS Broadcaster\PGDS-NET-CLIENT.cfg") Then
oFSO.MoveFile "C:\Program Files\PGDS-US\PGDS Broadcaster\PGDS-NET-CLIENT.cfg", sDirectory, false
End If

Thanks in advance,
Cowley
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
If not oFSO.FileExists("C:\Program Files\PGDS-US\PGDS Broadcaster\PGDS-NET-CLIENT.cfg") Then

I think what you want is

If not oFSO.FileExists(sDirectory & "\PGDS-NET-CLIENT.cfg") Then

or something along those lines

PJ
Answered 01/20/2010 by: pjgeutjens
Red Belt

Please log in to comment
0
Your first issue is that the "oFSO.MoveFile" will never execute, because you're telling your script to only execute that line if the file in your installdir is not found. Remove the "Not" as a first step, or change the file it's looking for to the my documents path.
Answered 01/20/2010 by: Jsaylor
Second Degree Blue Belt

Please log in to comment
0
Your first issue is that the "oFSO.MoveFile" will never execute, because you're telling your script to only execute that line if the file in your installdir is not found. Remove the "Not" as a first step, or change the file it's looking for to the my documents path.

Oh yeah lol well spotted [:D]
Answered 01/20/2010 by: MSIPackager
Third Degree Black Belt

Please log in to comment
0
Thanks for the input, I've gone a little bit further with this and made life easy for myself, whilst it works, I want to find a mechanism for it to run more than once without error.

The below script works fine If I'm running it for the first time under an account where the file doesn't exist in the destination location, my problem occurs when I re-run the script, basically because the file already exists in the destination location it errors. What logic would I need to use to prevent it from displaying an error when I re-run the script?

I'm guessing it's an If filesys.FileExists("O:\Data\My Documents\PGDS-NET-CLIENT.cfg") then do nothing type statement?

dim filesys
set filesys=CreateObject("Scripting.FileSystemObject")
If filesys.FileExists("C:\Program Files\PGDS-US\PGDS Broadcast Ticker\PGDS-NET-CLIENT.cfg") Then
filesys.MoveFile "C:\Program Files\PGDS-US\PGDS Broadcast Ticker\PGDS-NET-CLIENT.cfg", "O:\Data\My Documents\"
End If
Answered 01/20/2010 by: cowley
Orange Belt

Please log in to comment
0
You can use AND statements nested inside of IF's. So try:

if filesys.fileexists("SOURCEFILE") AND NOT filesys.fileexists("Destination") Then.....
Answered 01/20/2010 by: Jsaylor
Second Degree Blue Belt

Please log in to comment
0
Thanks for your help on this Jsaylor, can I just clarify what you mean because I've tried what I think you mean and my script editor is unable to resolve it. Sorry for so many questions.

Here's my new script...the one that doesn't appear to work;

dim filesys
set filesys=CreateObject("Scripting.FileSystemObject")
if filesys.fileexists("C:\Program Files\PGDS-US\PGDS Broadcast Ticker\PGDS-NET-CLIENT.cfg") AND NOT filesys.fileexists ("O:\Data\My Documents\PGDS-NET-CLIENT.cfg")
Then
filesys.MoveFile "C:\Program Files\PGDS-US\PGDS Broadcast Ticker\PGDS-NET-CLIENT.cfg", "O:\Data\My Documents\"
End If
Answered 01/20/2010 by: cowley
Orange Belt

Please log in to comment
0
Cowley,

perhaps, instead of using the MoveFile function, in which you cannot supply an overwrite parameter, you could use a combination of CopyFile (where you CAN specify Overwrite behaviour) and a DeleteFile

PJ
Answered 01/20/2010 by: pjgeutjens
Red Belt

Please log in to comment
0
ORIGINAL: pjgeutjens

Cowley,

perhaps, instead of using the MoveFile function, in which you cannot supply an overwrite parameter, you could use a combination of CopyFile (where you CAN specify Overwrite behaviour) and a DeleteFile

PJ


Cheers for the heads up, I tried this method but my script editor doesn't like it :(

dim filesys
set filesys=CreateObject("Scripting.FileSystemObject")
if filesys.FileExists("C:\Program Files\PGDS-US\PGDS Broadcast Ticker\PGDS-NET-CLIENT.cfg") then
if not filesys.FileExists("O:\Data\My Documents\PGDS-NET-CLIENT.cfg") Then filesys.CopyFile "C:\Program Files\PGDS-US\PGDS Broadcast Ticker\PGDS-NET-CLIENT.cfg", "O:\Data\My Documents\PGDS-NET-CLIENT.cfg"
filesys.Deletefile "C:\Program Files\PGDS-US\PGDS Broadcast Ticker\PGDS-NET-CLIENT.cfg"
End if
Answered 01/20/2010 by: cowley
Orange Belt

Please log in to comment
0
ORIGINAL: cowley

Thanks for your help on this Jsaylor, can I just clarify what you mean because I've tried what I think you mean and my script editor is unable to resolve it.  Sorry for so many questions.

Here's my new script...the one that doesn't appear to work;

dim filesys
set filesys=CreateObject("Scripting.FileSystemObject")
if filesys.fileexists("C:\Program Files\PGDS-US\PGDS Broadcast Ticker\PGDS-NET-CLIENT.cfg") AND NOT filesys.fileexists ("O:\Data\My Documents\PGDS-NET-CLIENT.cfg")
Then
filesys.MoveFile "C:\Program Files\PGDS-US\PGDS Broadcast Ticker\PGDS-NET-CLIENT.cfg", "O:\Data\My Documents\"
End If


Are you by chance getting the "expected 'Then'" error when you run that script? Your "Then" appears to be on a separate line from your "if," which will confuse and explode a vbs.
Answered 01/20/2010 by: Jsaylor
Second Degree Blue Belt

Please log in to comment
0
filesys.CopyFile "C:\Program Files\PGDS-US\PGDS Broadcast Ticker\PGDS-NET-CLIENT.cfg", "O:\Data\My Documents\PGDS-NET-CLIENT.cfg"

You'll want to specify the overwrite parameter,

CopyFile Source, Destination, False <- - the overwrite parameter

PJ
Answered 01/20/2010 by: pjgeutjens
Red Belt

Please log in to comment
0
Gents, was there some reason why you were all ignoring the MoveFile table? If persisting with script, PLEASE, PLEASE remove the continuous use of the same text and use variables! If the source/destination ever moves, it'll be somewhat easier to change the data once, rather than at every occurence.
Answered 01/20/2010 by: VBScab
Red Belt

Please log in to comment
0
Baby steps vbscab, baby steps.
Answered 01/20/2010 by: Jsaylor
Second Degree Blue Belt

Please log in to comment
0
probably better to use the current user healing techniques here as movefile table may only work for initial user and not successive users.

I do agree throwing away the vb script is the way forward.
Answered 01/20/2010 by: jmcfadyen
Fifth Degree Black Belt

Please log in to comment
0
What logic would I need to use to prevent it from displaying an error when I re-run the script?


cowley

u can use "On Error Resume Next" in ur script.

see if it helps.
Answered 01/20/2010 by: dnmech
Senior Purple Belt

Please log in to comment
0
Gents, was there some reason why you were all ignoring the MoveFile table?

In my case it was lack of coffee, you are right ofcourse.
Unless the script is meant for some sort of Active Setup operation, to be run for each user.

PJ
Answered 01/20/2010 by: pjgeutjens
Red Belt

Please log in to comment
0
u can use "On Error Resume Next" in ur script. That step is only worthwhile if errors are subsequently trapped. As usual, the script is barren of a single line of error-trapping.

Also, I believe it may have been mentioned before that English may not necessarily be forum users' first language so please avoid the abomination of text-speak in posts. Thanks.

Lastly, @OP, there is a dedicated Scripting forum on AppDeploy.
Answered 01/21/2010 by: VBScab
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity