Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - VBScript problems

Reply
 
Old 06-27-2009   #1 (permalink)
Sudhakar


 
 

VBScript problems

I want to copy the contents of "SourceDir" directory to "TargetDir" directory
in

Windows XP,

say,
TargetDir = C:\SAS
SourceDir = C:\SASLatest
BackupDir = C:\SASBackup

Both the above directories contains files and subfolders and sub-subfolders
The approach I would follow is,

1) Take a backup of TargetDir
2) Empty the TargetDir
3) Copy the contents of SourceDir to TargetDir
4) If copy is successful
{
delete the BackupDir
}
else If copy is not successfull
{
restore the sourceDir i.i. copy the contents of BackupDir to SourceDir
}

I wrote an vbscript for the above operation ?

My doubts:


1) Can I use FileSystemObject.CopyFolder method for copying files and
folders recursively ?
sometimes, I get permission denied error, i rectified and i still suspect
whether I'll get that error, will the CopyFolder method of FSO is reliable ?
Can I use , XCOPY cmd of DOS using to copy files and folders instead ?
Please anybody suggest which one is best

2) Does the VBscript has any main() , I just declare the variables using Dim
statement and then immediately start the processing, Is that correct or I
should have any main() procedure ?

3) I need to call this VBScript from inside a C++ program. I thought of
ShellExecute API to call the VBScript. But i was told that, the "open" verb
for the vbsript might be disabled , so I need to call the WSCript.exe
explicitly to call the VBScript.
How i enable the open verb for VBScript so thatit runs without any problem ?
How to obtain the path for wscript.exe in the PC or how to make it as the
default engine for VBScript?

4) when the CopyFolder method is used, How to get a copy progress bar ?
I know that it is available in
Shell.Application.Namespace object, CopyHere method
I used likem

Dim objShell
Set objShell = WScript.CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace("C:\targetFolder")
objFolder.CopyHere "C:\SourceFolder",16

---- to display the progress bar while copying, bu the problem here is that ,

"targetfolder " itself is copied under C:\SourceFolder, but i wnat to copy
the contents of C:\targetfolder to C:\sourcefolder, thats why I dint opted
for CopyHere, how to achiev this in CopyHere method


thanks,
Sudhakar

My System SpecsSystem Spec
Old 06-27-2009   #2 (permalink)
Pegasus [MVP]


 
 

Re: VBScript problems

*** See below.

"Sudhakar" <Sudhakar@xxxxxx> wrote in message
news:CB30BECB-E0DA-4B65-AC31-4AC0AB8285DC@xxxxxx
Quote:

>I want to copy the contents of "SourceDir" directory to "TargetDir"
>directory
> in
>
> Windows XP,
>
> say,
> TargetDir = C:\SAS
> SourceDir = C:\SASLatest
> BackupDir = C:\SASBackup
>
> Both the above directories contains files and subfolders and
> sub-subfolders
> The approach I would follow is,
>
> 1) Take a backup of TargetDir
> 2) Empty the TargetDir
> 3) Copy the contents of SourceDir to TargetDir
> 4) If copy is successful
> {
> delete the BackupDir
> }
> else If copy is not successfull
> {
> restore the sourceDir i.i. copy the contents of BackupDir to SourceDir
> }
>
> I wrote an vbscript for the above operation ?
>
> My doubts:
>
>
> 1) Can I use FileSystemObject.CopyFolder method for copying files and
> folders recursively ?
> sometimes, I get permission denied error, i rectified and i still suspect
> whether I'll get that error, will the CopyFolder method of FSO is reliable
> ?
*** The File System Object is totally reliable. If you get permission errors
*** then it's either because of a permission issue or because of an error
*** in your program.
Quote:

> Can I use , XCOPY cmd of DOS using to copy files and folders instead ?
> Please anybody suggest which one is best
*** Copying files and folders is a standard administrator's task for
*** which there are fully developed console commands with a rich
*** set of switches. Using xcopy.exe or robocopy.exe requires
*** about one tenth of the code that the equivalent VB Script does.
*** Note, by the way, that DOS is a legacy operating system that
*** was first introduced in about 1978 and was last used with Windows
*** ME. It is not available under WinXP. The Command Console may
*** be black but inside it is radically different from DOS.
Quote:

> 2) Does the VBscript has any main() , I just declare the variables using
> Dim
> statement and then immediately start the processing, Is that correct or I
> should have any main() procedure ?
*** You don't need a main() procedure in VB Script. Have a look at
*** the examples you see in this newsgroup!
Quote:

>
> 3) I need to call this VBScript from inside a C++ program. I thought of
> ShellExecute API to call the VBScript. But i was told that, the "open"
> verb
> for the vbsript might be disabled , so I need to call the WSCript.exe
> explicitly to call the VBScript.
> How i enable the open verb for VBScript so thatit runs without any problem
> ?
> How to obtain the path for wscript.exe in the PC or how to make it as the
> default engine for VBScript?
*** If you want to write robust applications then you should invoke
*** your VB Scripts like so:
*** cscript //nologo c:\Scripts\SomeScript.vbs
*** or maybe
*** wscript //nologo c:\Scripts\SomeScript.vbs
Quote:

> 4) when the CopyFolder method is used, How to get a copy progress bar ?
> I know that it is available in
> Shell.Application.Namespace object, CopyHere method
> I used likem
*** Have a look here:
http://www.microsoft.com/technet/scr....mspx?mfr=true
http://www.microsoft.com/technet/scr...6/hey1010.mspx
Quote:

> Dim objShell
> Set objShell = WScript.CreateObject("Shell.Application")
> Set objFolder = objShell.NameSpace("C:\targetFolder")
> objFolder.CopyHere "C:\SourceFolder",16
>
> ---- to display the progress bar while copying, bu the problem here is
> that ,
>
> "targetfolder " itself is copied under C:\SourceFolder, but i wnat to copy
> the contents of C:\targetfolder to C:\sourcefolder, thats why I dint opted
> for CopyHere, how to achiev this in CopyHere method
>
>
> thanks,
> Sudhakar

My System SpecsSystem Spec
Old 07-01-2009   #3 (permalink)
Mark D. MacLachlan


 
 

Re: VBScript problems

Sudhakar wrote:
Quote:

> I want to copy the contents of "SourceDir" directory to "TargetDir"
> directory in
>
> Windows XP,
>
> say,
> TargetDir = C:\SAS
> SourceDir = C:\SASLatest
> BackupDir = C:\SASBackup
>
> Both the above directories contains files and subfolders and
> sub-subfolders The approach I would follow is,
>
> 1) Take a backup of TargetDir
> 2) Empty the TargetDir
> 3) Copy the contents of SourceDir to TargetDir
> 4) If copy is successful
> {
> delete the BackupDir
> }
> else If copy is not successfull
> {
> restore the sourceDir i.i. copy the contents of BackupDir to
> SourceDir }
>
> I wrote an vbscript for the above operation ?
>
> My doubts:
>
>
> 1) Can I use FileSystemObject.CopyFolder method for copying files and
> folders recursively ?
> sometimes, I get permission denied error, i rectified and i still
> suspect whether I'll get that error, will the CopyFolder method of
> FSO is reliable ? Can I use , XCOPY cmd of DOS using to copy files
> and folders instead ? Please anybody suggest which one is best
>
> 2) Does the VBscript has any main() , I just declare the variables
> using Dim statement and then immediately start the processing, Is
> that correct or I should have any main() procedure ?
>
> 3) I need to call this VBScript from inside a C++ program. I thought
> of ShellExecute API to call the VBScript. But i was told that, the
> "open" verb for the vbsript might be disabled , so I need to call the
> WSCript.exe explicitly to call the VBScript.
> How i enable the open verb for VBScript so thatit runs without any
> problem ? How to obtain the path for wscript.exe in the PC or how
> to make it as the default engine for VBScript?
>
> 4) when the CopyFolder method is used, How to get a copy progress bar
> ? I know that it is available in
> Shell.Application.Namespace object, CopyHere method
> I used likem
>
> Dim objShell
> Set objShell = WScript.CreateObject("Shell.Application")
> Set objFolder = objShell.NameSpace("C:\targetFolder")
> objFolder.CopyHere "C:\SourceFolder",16
>
> ---- to display the progress bar while copying, bu the problem here
> is that ,
>
> "targetfolder " itself is copied under C:\SourceFolder, but i wnat to
> copy the contents of C:\targetfolder to C:\sourcefolder, thats why I
> dint opted for CopyHere, how to achiev this in CopyHere method
>
>
> thanks,
> Sudhakar
I'd also recommend you take a look scripting ROBOCOPY. Depending on
the data in the folders, you might determine you only want to copy
newer and changed files which would dramatically reduce your backup
times. You can use the /XO switch for that.

Hope that helps.

Regards,

Mark D. MacLachlan

--

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
CSS and VBscript VB Script
VBscript Help VB Script
How to do No hang up VBScript (nohup for VBScript) VB Script
Powershell Wrapper Script Problems - Trying to Call PowershellExchange 2007 Commands from Secondary Language (Like VBScript) PowerShell
vbscript and HTA help VB Script


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46