Easy one I think! - Help with VBScript
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
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
Answers (16)
Please log in to answer
Posted by:
pjgeutjens
14 years ago
Posted by:
Jsaylor
14 years ago
Posted by:
MSIPackager
14 years ago
Posted by:
cowley
14 years ago
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
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
Posted by:
Jsaylor
14 years ago
Posted by:
cowley
14 years ago
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
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
Posted by:
pjgeutjens
14 years ago
Posted by:
cowley
14 years ago
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
Posted by:
Jsaylor
14 years ago
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.
Posted by:
pjgeutjens
14 years ago
Posted by:
anonymous_9363
14 years ago
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.
Posted by:
jmcfadyen
14 years ago
Posted by:
dnmech
14 years ago
Posted by:
pjgeutjens
14 years ago
Posted by:
anonymous_9363
14 years ago
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.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.