By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,601 Members | 1,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,601 IT Pros & Developers. It's quick & easy.

VB Script one of the Method help Needed

P: 1
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
Share this Question
Share on Google+
1 Reply


P: 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

Post your reply

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