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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie requesting help. Script will not preform all copy's. 1

Status
Not open for further replies.
Joined
Dec 4, 2003
Messages
4
Location
US
I want to thank everyone up front. I have a script where I am checking for the existence of a file, if not found copy some other files from one server location to another, then copy a link file to the desktop. The first copy seems to work, but then the script goes back to the main script and does not perform the other copies. Any suggestions would be appreciated.

CODE:

Option Explicit
Const OverwriteExisting = True
Dim objFSO, WSHShell, WSHEnv, sUserName, Mail6location, bMail6Exists

' ************ Start Span *****************
call getuser()
filecheck()


' Sub to get the username
sub getuser()
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set WSHEnv = WSHShell.Environment("Process")
sUserName = WSHEnv("USERNAME")
'msgbox sUserName
end sub

' Sub to check for the file
sub filecheck()
If NOT objFSO.FileExists("\\server1\r_mydocuments$\" & sUserName & "\Notes\Data\Mail6.ntf") Then
Set objFSO = CreateObject("Scripting.FileSystemObject")
msgbox "begin copy routine 1"
objFSO.CopyFile "\\server1\r_mydocuments$\N6ntf\*.ntf" , "\\server1\r_mydocuments$\" & sUserName & "\Notes\Data\" , OverwriteExisting
msgbox "begin copy routine 2"
objFSO.CopyFile "\\server1\r_mydocuments$\" & sUserName & "\Notes\notes.ini" , "\\server1\r_mydocuments$\" & sUserName & "\Notes\Data\notes.ini"
msgbox "begin copy routine 3"
objFSO.CopyFile "\\server1\notes601$\*.lnk" , "C:\Docume~1\" &sUserName& "\desktop\" , OverwriteExisting
Else
cscript.quit
End If
Msgbox "end sub filecheck"
end sub

set WSHShell = nothing
set WSHEnv = nothing
set objFSO = nothing

msgbox "script complete"
' End script
 
Hello mtbrain200,

I see some flaws in logic & syntax on the surface of it.
[1] There is no such thing as cscript.quit.
[2] You use objfso before setting it up.
[3] Global scope is not necessary for some variable.
[4] Destroy objects in reverse order of their creation.
[5] You have to make sure files being copied or overwritten do not have read-only attribute.
Here is a preliminary revision see how it works.
Code:
Option Explicit
Const OverwriteExisting = True
Dim sUserName, Mail6location, bMail6Exists

'  ************   Start Span    *****************
call getuser()
filecheck()


'  Sub to get the username
sub getuser()
Dim WSHShell, WSHEnv
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set WSHEnv = WSHShell.Environment("Process")
sUserName = WSHEnv("USERNAME")
'msgbox sUserName
Set WSHEnv = nothing
Set WSHShell = nothing
end sub

'  Sub to check for the file
sub filecheck()
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
If NOT objFSO.FileExists("\\server1\r_mydocuments$\" & sUserName & "\Notes\Data\Mail6.ntf") Then
    msgbox "begin copy routine 1"
    objFSO.CopyFile "\\server1\r_mydocuments$\N6ntf\*.ntf" , "\\server1\r_mydocuments$\" & sUserName & "\Notes\Data\" , OverwriteExisting 
    msgbox "begin copy routine 2"
    objFSO.CopyFile "\\server1\r_mydocuments$\" & sUserName & "\Notes\notes.ini" , "\\server1\r_mydocuments$\" & sUserName & "\Notes\Data\notes.ini"
    msgbox "begin copy routine 3"
    objFSO.CopyFile "\\server1\notes601$\*.lnk" , "C:\Docume~1\" &sUserName& "\desktop\" , OverwriteExisting
Else
    Set objFSO = nothing
    WScript.Quit    'if you really want to
End If
Set objFSO = nothing
Msgbox "end sub filecheck"
end sub

msgbox "script complete"
' End script
regards - tsuji
 
Thanks tsuij!!! This worked great!

Hopefully I won't make these mistakes again. =)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top