473,320 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

VB Script one of the Method help Needed

Hi,

Can any one suggest me , method which is available in VB Script to copy the number of FILES which is available in a folder to another folder in another Drive (Say for example Z :/-Drive one of the folder to C:/ Drive one of the existing folder ) .

Kindly let me know if you need more information..

Thanks in Adavance !

Regards,
Nagaraj
Sep 23 '07 #1
1 1013
Knut
1
Save this with File Extention .vbs


Expand|Select|Wrap|Line Numbers
  1. '---------------------------------------------------------
  2. 'Written by Vic Laurie, January, 2006
  3. 'Modified by Knut H, October 2007
  4. 'All rights reserved. Provided as is
  5. 'with no guarantees, express or implied
  6. 'User assumes all responsibility
  7. '---------------------------------------------------------
  8.  
  9. 'Description- Copies files with specified extension from user selected
  10. 'folder and its subfolders to a user selected destination folder.
  11. 'Pre-existing files of the same name will be overwritten
  12. 'if they are older than the file being copied.
  13. 'Uses Xcopy with switches /c /h /k /r /y /i /q /s /d
  14.  
  15. Option Explicit
  16. Dim sFldrInput1, sFldrInput2, introMsg, sExtension
  17. introMsg = msgBox("This program copies files from a specified folder." & vbCrLf & "Files from subfolders will also be copied." & vbCrLf & "Pre-existing files of the same name will be overwritten if they are older."& vbCrLf & "If you are copying many files it may take a few minutes."& vbCrLf & "A message will appear when copying is finished.",vbOKCancel)
  18. If introMsg = vbCancel Then
  19.     Wscript.Quit
  20. End If
  21. ChooseFolder sFldrInput1,"Select the source folder:"
  22. ChooseFolder sFldrInput2, "Select the destination folder:" & vbCrLf & "Choose New Folder and type the folder name you want, unless you want to use an existing folder." & vbCrLf & "The script has to be modified further if you want to copy existing folder names as well." 
  23. ChooseExtension sExtension
  24. CopyFiles sFldrInput1, sFldrInput2, sExtension
  25. Wscript.Quit
  26.  
  27.  
  28. sub ChooseFolder(sFldrChoice, sSelectionString)
  29. dim objShell, objFolder, objFolderItem, strPath, msgValue
  30. Const DESK_TOP = &H10&
  31. Const WINDOW_HANDLE = 0
  32. Const OPTIONS = 0
  33. sFldrChoice = ""
  34. Set objShell = CreateObject("Shell.Application")
  35. Set objFolder = objShell.Namespace(DESK_TOP)
  36. Set objFolderItem = objFolder.Self
  37. strPath = objFolderItem.Path
  38. Set objShell = CreateObject("Shell.Application")
  39. Set objFolder = objShell.BrowseForFolder _
  40.     (WINDOW_HANDLE, sSelectionString, OPTIONS, strPath) 
  41.  
  42. If objFolder Is Nothing Then
  43.     Wscript.Quit
  44. End If
  45.  
  46. Set objFolderItem = objFolder.Self
  47. sFldrChoice = objFolderItem.Path
  48.  
  49. msgValue = msgBox("You selected "& sFldrChoice, vbOKCancel)
  50. If msgValue = vbCancel Then
  51.     Wscript.Quit
  52. End If
  53. If Len(sFldrChoice) = 3 then 
  54.    chkForDrv sFldrChoice
  55. End if
  56. End sub
  57.  
  58. sub CopyFiles (sSourceFldr,sBkupFldr, sExtension)
  59.  
  60. Const CopyX = "xcopy "
  61. Const sWildCard = "\*."
  62. Const sSwitches = " /c /h /k /r /y /i /q /s /d"
  63. dim sStatement
  64. dim objWshell
  65. Dim oIE, oIEDoc, sMsg
  66. sStatement= copyX  & chr(34) & sSourceFldr & sWildcard  & sExtension & chr(34) & " " & chr(34) & sBkupFldr & chr(34) & sSwitches
  67.  
  68. 'The next part is just to display a message while copying
  69. set objWshell=Wscript.CreateObject("Wscript.Shell")
  70. Set oIE = Wscript.CreateObject("InternetExplorer.Application")
  71. oIE.Navigate "about:blank"
  72. do while oIE.busy : wscript.sleep 10 : loop
  73. Set oIEDoc = oIE.Document
  74. oIE.AddressBar = False
  75. oIE.StatusBar = False
  76. oIE.ToolBar = False
  77. oIE.height=200
  78. oIE.width=300
  79. oIE.Resizable = False
  80. oIE.Visible = True
  81. sMsg= "<p><center>Files are being copied.<br>Please wait.<br>Large folders may take several minutes.</center></p>"
  82. oIEDoc.Body.Innerhtml= sMsg
  83.  
  84. 'copy the files
  85. objWshell.Run sStatement,7,true
  86.  
  87. Set oIEDoc = Nothing
  88. oIE.Quit
  89. Set oIE = Nothing
  90. set objWshell = Nothing
  91. msgBox "Copying job done"
  92. End sub
  93.  
  94. Sub chkForDrv(sFldrChoice)
  95. Dim oRe, bMatch
  96. set oRe = New RegExp
  97. oRe.pattern = "[a-zA-Z]:\\$"
  98. bMatch= oRe.Test(sFldrChoice)
  99. If bMatch Then sFldrChoice= Left(sFldrChoice, 2)
  100. End sub
  101.  
  102. Sub ChooseExtension(sExtension)
  103.  
  104.  
  105. 'Changed this to copy any file in selected folder
  106. sExtension = "*"
  107.  
  108. 'Original script used this:
  109. 'sExtension = InputBox("Enter extension of files to be copied.", "Name of extension")
  110.  
  111. If sExtension = "" Then
  112.     Wscript.Quit
  113. End If
  114. chkForDot sExtension
  115. End sub
  116.  
  117. Sub chkForDot(sExtension) 
  118. Dim lenExt, truncStr
  119. lenExt = Len(sExtension)
  120. truncStr =left(sExtension,1)
  121. If truncStr = "." then
  122.     sExtension = right(sExtension,lenExt-1)
  123. End if
  124. End sub
Oct 9 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: deko | last post by:
In regard to running php scripts with cron - Here is a sample script: <?php //debug.php echo "<br> This is a test"; ?> I can call debug.php from a web page on my site like this:
1
by: Les Juby | last post by:
A year or two back I needed a search script to scan thru HTML files on a client site. Usual sorta thing. A quick search turned up a neat script that provided great search results. It was fast,...
1
by: Mike Biang | last post by:
Is there a way to request a server script through javascript without having the browser navigate to another page? Similar to the effects of calling the server.execute method in ASP. Is anyone...
3
by: Nath | last post by:
Please help!? I am new to writing html, javascript, pretty new to MySQL but quite proficient at writing Perl and i'm a quick learner. I am building a database driven website and i am a little...
4
by: Ian Giblin | last post by:
I am an experienced C programmer, learning C++ by writinging a mathematical toolkit in the framework of a script interpreter. I am posting here to ask for advice (or references) on the object...
4
by: Bob Sanderson | last post by:
I have a script that reads the computer date and writes it to a copyrite footer on a web page. The idea is to avoid having to update each page manually at the start of a new year. It works fine...
0
by: ZMan | last post by:
Scenario: This is about debugging server side scripts that make calls to middle-tier business DLLs. The server side scripts are legacy ASP 3.0 pages, and the DLLs are managed DLLs...
2
by: kelly | last post by:
Hi, I don't have a code to show you, what I need are references or algorithms so that I'm in a right track. By the way, thanks for introducing me the array or arrays. Now I can continue my...
3
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.