• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2336
  • Last Modified:

VBScript to determine drive letter, copy all files and folder and show a progress bar

I am looking for some VBScript that will be run from a USB memory stick.

Its first job is to discover what the drive letter of the USB memory stick is. The script will be copied to several different makes of USB drives so it cannot be determined by make/model, etc.

The second job it to copy all the files and folders within 1 directory on the USB memory stick to a location on the host PC.
Copy X:\Builds\Build1 C:\Temp\Build1
(where X = the discovered drive letter)

The third job is to show an accurate progress bar during the copying.

1 Solution
You can set static drive letters for removable devices such as a USB drive in Computer Management under Storage > Disk Management.

You can use modified VBS file/folder copy script tailored to that drive letter.
I would start here with a template:

You could set this script to run as a scheduled task, or manually run it as needed.

As for a detailed progress bar, it does not exist in windows.
We all want it. Microsoft refuses to deliver.
Bill PrewCommented:
Can you be more specific about what files will need to be copied to the host PC?  Are they all in one folder, are there subfolders, is it a list of files, etc?

Hi, with this script located in the X:\Builds folder, this should copy the X:\Builds\Build1 folder to the C:\Temp folder on the computer you run it on.

The script uses a relative path to the the current folder of the script to find the Build1 folder on the USB drive.



strSourceFolder = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "Build1\"
strTargetFolder = "C:\Temp\"

If Right(strSourceFolder, 1) <> "\" Then strSourceFolder = strSourceFolder & "\"
If Right(strTargetFolder, 1) <> "\" Then strTargetFolder = strTargetFolder & "\"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strSourceFolder)

Set objShellApp = CreateObject("Shell.Application")
Set objFolder = objShellApp.NameSpace(strTargetFolder)

If Not objFolder Is Nothing Then
	'MsgBox "Copying " & objFile.Path & " to " & strTargetFolder
	objFolder.CopyHere strSourceFolder, FOF_CREATEPROGRESSDLG
	WScript.Echo "There was an error finding " & strTargetFolder
End If

Open in new window

fruitloopyAuthor Commented:
Thanks Rob, that works great.
No problem. Thanks for the grade.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now