copy from one source folder to multiple usb drives

I'm looking for a script (bat, vbs, robocopy cmd) that would copy folder from local c: drive to multiple usb drives plug into a hub.  A plus for the script would detect the usb drive and auto start copy command (source to USB\drive).  The drive letters could change from pc to pc.
sully1116Asked:
Who is Participating?
 
spinzr0Commented:
I had to do something similar once, this code should do it.  Just change the first line to be your folder path.
sFolderToCopy = "C:\Test"

Set oFS = CreateObject("Scripting.FileSystemObject")
Set dUSBKeys = ScanForUSBKeys()
For Each oUSBKey in dUSBKeys.Keys
    If Left(oUSBKey, 1) = "\" Then
        sKey = oUSBKey
    Else
        sKey = oUSBKey & "\"
    End If
    oFS.CopyFolder sFolderToCopy, sKey
Next
Set dUSBKeys = Nothing
Set oFS = Nothing

Msgbox "Done."

Function ScanForUSBKeys()
    Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
    Set dTemp = CreateObject("Scripting.Dictionary")

    Set cDisks = oWMI.ExecQuery("Select InterfaceType,MediaType,PNPDeviceID,DeviceID,Size from Win32_DiskDrive")
    For Each oDisk in cDisks
        If InStr(LCase(oDisk.InterfaceType),"usb") > 0 AND InStr(LCase(oDisk.MediaType),"removable") > 0 _
          AND InStr(LCase(oDisk.PNPDeviceID),"blackberry") = 0 AND InStr(LCase(oDisk.PNPDeviceID),"ipod") = 0 _
          AND NOT oDisk.PNPDeviceID = "" Then
            Set cDrivePartitions = oWMI.ExecQuery("ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" & _
                                  oDisk.DeviceID & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition" )
            For Each oDrivePartition in cDrivePartitions
                Set cDriveLetters = oWMI.ExecQuery("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" & _
                                    oDrivePartition.DeviceID & "'} WHERE AssocClass = Win32_LogicalDiskToPartition")
                For Each oDriveLetter in cDriveLetters
                    dTemp.Add oDriveLetter.DeviceID, 1
                Next
                Set cDriveLetters = Nothing
            Next
            Set cDrivePartitions = Nothing
        End If
    Next
    Set cDisks = Nothing
    Set ScanForUSBKeys = dTemp
    Set dTemp = Nothing
    Set oWMI = Nothing
End Function

Open in new window

0
 
SiddharthRoutCommented:
0
 
aikimarkCommented:
@sully1116

When I read this question, I thought you wanted to implement a software distribution mechanism.  However, the 'automatic' nature of your request has real world consequences, since the script might copy the directory to any thumb drive connected to the system.

Although the Sid link gets you started, it doesn't address version control and performance issues.  What are you trying to accomplish with these thumb drives?
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
sully1116Author Commented:
Thank you for all responses./

spinzr0 the script looks good, will the script continue to copy source to the rest of the usb drives?  In a control environment I will have one PC plug into a 10 port USB hub.  I will need the source data (c:\Source) to replicate to all usb drives plug in.
0
 
aikimarkCommented:
You might also look at commercial copiers
Software:
http://www.usbduplicatornow.com/
http://www.softcns.com/utilities/review-usb-duplicator-now_97559.html
There are also hardware duplicators.
0
 
spinzr0Commented:
Yes, it will detect any attached USB key and loop to do all of them.
0
 
aikimarkCommented:
@sully1116

My earlier comment holds some questions you might want to address.  If you are plugging in a thumbdrive that you copied to before, do you need the existing content deleted before the copy?  Should the prior content be checked to be sure it is back-level before a copy is done?

Is the process you're looking for going to run continuously?

How important is speed?
0
 
sully1116Author Commented:
Spinzr0, your script works great!  Thank you.
0
 
sully1116Author Commented:
aikimark, content needs to be copied  / added.  Prior content is no longer needed but will not cause problems.  The process is not continously.  Speed is not that big of a concern because size of data will only be around 4-7 gb.
0
 
aikimarkCommented:
The method you have accepted and will be using is a serial copy method.  If you do find performance to be a problem in the future, you can use the code to
1. determine the target drives
2. create a batch file to do the copying
3. shell the batch file

===
The batch file will have a START statement for each of the copy operations and may also include some pre-copy cleanup.  If you are copying 4-7 GB to an 8GB thumb drive, you might not have room for subsequent copy operations.

If you use Robocopy, instead of XCOPY or Copy, you might also gain some speed if the source file hasn't changed.  It can also remove target files that aren't matched by a source file.
http://technet.microsoft.com/en-us/library/cc733145(WS.10).aspx

Note: since you would be trying to copy to many different thumbdrives at once, you probably shouldn't use the /MT flag to employ multi-threading. (available with the Win7 version of Robocopy)

====
If you are running on one of the 64-bit versions of Windows and have lots of physical memory, you might also consider using a RAMDISK to place all the source files in memory.
http://msdn.microsoft.com/en-us/library/ff544551(v=vs.85).aspx
Note: there are other RAMDisk drivers/utilities from different vendors.

====
There are other utilities that cache hard drive contents in RAM.

There is at least one hybrid hard drive that does the caching on the drive.  

For both of these solution paths, your multiple copy operations would be able to read from cache once the first of the operations had caused a physical disk read.

Good luck.
0
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.

All Courses

From novice to tech pro — start learning today.