Re: CopyHere
- From: "Paul Randall" <Paulr901@xxxxxxxxxxxx>
- Date: Wed, 19 Aug 2009 16:52:51 -0600
Four comments, inline
"Eric" <someone@xxxxxxxxxxxxxxxxx> wrote in message
news:O92O8tQIKHA.1988@xxxxxxxxxxxxxxxxxxxxxxx
"Paul Randall" <Paulr901@xxxxxxxxxxxx> wrote in message
news:%234HwKHQIKHA.5956@xxxxxxxxxxxxxxxxxxxxxxx
Comments inlineYou explained why the script would continue if it was unable to copy
"Eric" <someone@xxxxxxxxxxxxxxxxx> wrote in message
news:%23mxY6NPIKHA.1684@xxxxxxxxxxxxxxxxxxxxxxx
On Error Resume Next does not apply here.
If the statement is there and not commented out, it applies.
files, which wasn't the question.
The question was asking for help on a CopyHere command which was not
creating a directory that doesn't exist.
The question was about the CopyHere command creating a directory that
doesn't exist on 75% of his computers and not creating a directory on 25%,
and his wanting help with the 25%. To be exact, the following are his exact
words:
>>>>>I am having a similar problem. My code is below. The copyhere will
not
>>>>>automatically create the directory if it doesn't already exist.
Weird
>>>>>thing is that it will automatically create the directory if it
doesn't
>>>>>exist on 75% of the machines I have but not the other 25%. Any help
you
>>>>>could provide would be greatly appreciated.
Telling him why he doesn't see an error doesn't help fix the problem of
not copying the files.
Your answer only seems to suggest removing the on error statement from a
script which is executed by end users in order to show them messages they
likely won't understand.
The comments in the code just say the code is trying to backup (copy)He's not trying to run through the copy command whether it copies or not
The comments in the code may tell what he is trying to do. The code can
only tell what he IS doing, not what he intends to do. The code says he
is running through the commands and taking the standard 'On Error Resume
Next' actions if and when any error occurs.
files.
Why do you care if the comments in the code tell what he intends to do?
Did you read the message above the code that tells what he expects it to
do??
Where do you see documentation that says CopyHere is supposed to createthen check for a message on why it failed.
If the issue is simply the command being expected to create a directory
that doesn't exist and it's not creating, just add a check and create
before the copy.
I think it is poor programming practice to design and implement a
workaround whenever it appears that some command does not work as the
documentation seems to say it should. This just leads to longer code and
less trust in the documentation. Removing the error obfuscating
statement, and reporting here any errors he cannot resolve by himself
might lead to better code, a better understanding of the command causing
the problem, and better trust in the documentation, and maybe an
understanding of what is different about the 25% of the machines with the
problem.
-Paul Randall
directories?
I don't see any such documentation, but James said it did work on 75% of his
computers. Allowing errors to be seen might give insights as to what is
going on.
The only official documentation I'm aware of on the command is at the MS
link I mentioned in the first post in this thread. I don't see that
there.
It is a poor programming practice to execute a command which does
something which is not documented and assume it's supposed to always do
that.
Proper practice would be to use the directory methods for checking
existance of and creating the directories.
Removing On Error Resume Next is always a bad idea for scripts to be used
by end users.
If James is talking about 75% and 25% of his computers, he is probably not
the typical end user, especially since he is posting his question here.
...If you want to see why something failed, put a fail check after that
statement.
If Err.Number <> 0 Then
errlog.WriteLine(Err.Description)
End If
Yes, code like this error logging is a good idea. Blindly throwing away all
error info and possibly having their execution order modifed, as James' code
does, is usually a liability.
-Paul Randall
http://www.devguru.com/technologies/VBScript/14059.asp
"Paul Randall" <Paulr901@xxxxxxxxxxxx> wrote in message
news:euyr0rOIKHA.2516@xxxxxxxxxxxxxxxxxxxxxxx
Perhaps it is time to learn about the "On Error Resume Next" statement.
When used in a main script, without other error handling statements, it
basically means:
1) Please don't inform the user when or where or why errors occur
2) Please change the order in which statements are executed, in various
ways, depending on where an error occurs
3) Please keep on going no matter how many errors occur.
The net result is that the user and script author do not have a clue as
to what statements may or may not have been executed when the script is
done.
-Paul Randall
"James" <dontemailme@xxxxxxxxxxxxxxx> wrote in message
news:O4tY2IOIKHA.4004@xxxxxxxxxxxxxxxxxxxxxxx
I am having a similar problem. My code is below. The copyhere will
not automatically create the directory if it doesn't already exist.
Weird thing is that it will automatically create the directory if it
doesn't exist on 75% of the machines I have but not the other 25%. Any
help you could provide would be greatly appreciated. This is pure vbs,
no hta or html involved.
On Error Resume Next
Set objNetwork = CreateObject("Wscript.Network")
Set objSHApp= CreateObject("Shell.Application")
Const FOF_CONFIRMALL = 16
Const FOF_SIMPLEPROGRESS = 256
Const FOF_CREATEDIR = 512
Set WshShell = WScript.CreateObject("WScript.Shell")
Set filesys = CreateObject("Scripting.FileSystemObject")
Set WshSysEnv = WshShell.Environment("PROCESS")
'Set destination
strDest = "G:\ProfileBackup\"
'Check if the ProfileBackup Folder exist, if not create it
If Not filesys.FolderExists(strDest) Then
filesys.CreateFolder(strDest)
End If
'Set source path strings
strHomePath = WshSysEnv("HOMEPATH")
strSrcDesktop = "c:" & strHomePath & "\desktop"
strSrcFavs = "c:" & strHomePath & "\Favorites"
strSrcMyDocs = "c:" & strHomePath & "\My Documents"
strSrcPsiData = "c:" & strHomePath & "\PsiData"
strSrcEmailSig = "c:" & strHomePath & "\Application
Data\Microsoft\Signatures"
' Using shell.application to copy since faster and displays
status/progress
'Backup User Desktop
objSHApp.Namespace(strDest).CopyHere strSrcDesktop,FOF_CONFIRMALL
'Backup User Favorites
objSHApp.Namespace(strDest).CopyHere strSrcFavs,FOF_CONFIRMALL
'Backup User My Documents
objSHApp.Namespace(strDest).CopyHere strSrcMyDocs,FOF_CONFIRMALL
'Backup User PsiData (Need to check if folder exists on PC first)
If filesys.FolderExists (strSrcPsiData) Then
objSHApp.Namespace(strDest).CopyHere strSrcPsiData,FOF_CONFIRMALL
End If
'Backup User Email Signatures (Need to check if folder exists on PC
first)
If filesys.FolderExists (strSrcEmailSig) Then
objSHApp.Namespace(strDest).CopyHere strSrcEmailSig,FOF_CONFIRMALL
End If
James
"Pegasus [MVP]" <news@xxxxxxxxxxxxx> wrote in message
news:%23yWJ$NEIKHA.5256@xxxxxxxxxxxxxxxxxxxxxxx
"Eric" <someone@xxxxxxxxxxxxxxxxx> wrote in message
news:eHK7rHEIKHA.1340@xxxxxxxxxxxxxxxxxxxxxxx
MS says CopyHere has options.
http://msdn.microsoft.com/en-us/library/bb787866(VS.85).aspx
I execute it with options and it ignores them. Am I missing
something or is MS missing something?
Let's have a look at your script!
.
- References:
- CopyHere
- From: Eric
- Re: CopyHere
- From: Pegasus [MVP]
- Re: CopyHere
- From: James
- Re: CopyHere
- From: Paul Randall
- Re: CopyHere
- From: Eric
- Re: CopyHere
- From: Paul Randall
- Re: CopyHere
- From: Eric
- CopyHere
- Prev by Date: Re: split textfile to more textfiles
- Next by Date: regional settings details
- Previous by thread: Re: CopyHere
- Next by thread: Re: CopyHere
- Index(es):
Relevant Pages
|
Loading