Share via

Using Robocopy in a batch file from usb

Anonymous
2012-03-05T13:40:08+00:00

I want to send some large files to a friend on a USB stick.  Because she's not very computer savy (I'm  not much more!) I wanted to create a batch file that would copy all folders and files  from the USB stick to her C:\USERS\PUBLIC folder.

Robocopy seemed the answer, but I don't know what the drive letter of the USB will be when used on her computer?

Tried just using Robocopy *.* /E C:\USERS\PUBLIC in the batch file

But then Robocopy thinks C:\users is the source.  Any ideas?

TIA

Trevor

Windows for home | Previous Windows versions | Files, folders, and storage

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-03-06T11:28:57+00:00

On the friend's computer, go to Computer management [type that in the Start menu search box], Storage, Disk management.  Select the drive, right click & assign it a particular drive letter, say K.  This letter always then applies to the USB device [not the USB port] when used on that computer.

RoboCopy syntax does not look like that for other commands as it works on entire folders not individual files.

ROBOCOPY  "K:" "C:\USERS\PUBLIC" /MIR

Will make a precise mirror-image copy of the K:\ drive into C:\USERS\PUBLIC, but for other actions such as simple copying see RoboCopy /? [type that in a Command window].  The /MIR switch removes files from C:\USERS\PUBLIC that do not exist in K:.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Anonymous
    2012-03-27T23:20:56+00:00
    1. Right click on the desktop and choose "New - Text Docoment".
    2. Rename the document to "FileCpyScript-robocopy_USB.bat" making sure you get rid of the ".txt"     extension at the end of the file.
    3. Right click on the new file and choose "Edit" and paste the text starting with "@echo off" below into the new file and save it....this will change the USB drive to "O" or any other drive letter you want to use, simply change the "O" in line 3 (subst O: %cd%) and make sure to also change it in the source directory variables below.

    Hope this helps you...

    @echo off

    verify on

    subst O: %cd%

    ::##########################################################################

    ::##   Script Version: v1.1                               /o)\       ##

    ::##                                                       (o/       ##

    ::##                                                                      ##

    ::##   NOTES:                                                             ##

    ::##   SCRIPT will copy all content, directories, and subdirectories      ##

    ::##########################################################################

    :://////////////////////////////////////////////////////////////////////////

    ::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

    :: -------- ALL VARs Listed/Modified Here --------

    set DIR1=DIR1-Results.txt

    set srceDIR1=O:\

    set trgtDIR1=C:\USERS\PUBLIC

    set DIR2=DIR2-Results.txt

    set srceDIR2=

    set trgtDIR2=

    set DIR3=DIR3-Results.txt

    set srceDIR3=

    set trgtDIR3=

    set DIR4=DIR4-Results.txt

    set srceDIR4=

    set trgtDIR4=

    set DIR5=DIR5-Results.txt

    set srceDIR5=

    set trgtDIR5=

    set DIR6=DIR6-Results.txt

    set srceDIR6=

    set trgtDIR6=

    set DIR7=DIR7-Results.txt

    set srceDIR7=

    set trgtDIR7=

    set DIR8=DIR8-Results.txt

    set srceDIR8=

    set trgtDIR8=

    set DIR9=DIR9-Results.txt

    set srceDIR9=

    set trgtDIR9=

    set DIR10=DIR10-Results.txt

    set srceDIR10=

    set trgtDIR10=

    :: -------- ALL VARs Listed/Modified Here --------

    ::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

    :://////////////////////////////////////////////////////////////////////////

    :LOOP

    ECHO.

    ECHO ###################################################

    ECHO ##  This script will copy files from source vars ##

    ECHO ##  to target vars, each via a seperate process  ##

    ECHO ###################################################

    ECHO.

    ECHO.

    ECHO **************************************************

    ECHO         Select The Menu Option to Proceed

    ECHO **************************************************

    ECHO  1. Verify Source/Target Vars (path)

    ECHO  2. Execute FileCopy

    ECHO  3. Open Logs

    ECHO  Q. Quit

    ECHO **************************************************

    ECHO.

    SET Choice=

    SET /P Choice=Type the letter and press Enter:

    IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%

    ECHO.

    IF /I '%Choice%'=='1' GOTO verfyVARs

    IF /I '%Choice%'=='2' GOTO FileCopy

    IF /I '%Choice%'=='3' GOTO LnchLgs

    IF /I '%Choice%'=='Q' GOTO End

    ECHO.

    ECHO "%Choice%" is not valid. Please try again.

    ECHO.

    GOTO Loop

    :verfyVARs

    ECHO.

    ECHO ##############################################################

    ECHO  ****  Please verify all Source and Target Paths Below   ****

    ECHO  ****  NOTE: Only vars with a valid path will display    ****

    ECHO ##############################################################

    ECHO.

    ECHO -----------------------------------------------------------------

    PAUSE

    IF NOT [%srceDIR1%] EQU [] ECHO  %srceDIR1%

    IF NOT [%srceDIR1%] EQU [] ECHO * Copies TO *

    IF NOT [%trgtDIR1%] EQU [] ECHO  %trgtDIR1%

    ::

    IF NOT [%srceDIR2%] EQU [] ECHO -----------------------------------------------------------------

    IF NOT [%srceDIR2%] EQU [] ECHO  %srceDIR2%

    IF NOT [%srceDIR2%] EQU [] ECHO * Copies TO *

    IF NOT [%trgtDIR2%] EQU [] ECHO  %trgtDIR2%

    ::

    IF NOT [%srceDIR3%] EQU [] ECHO -----------------------------------------------------------------

    IF NOT [%srceDIR3%] EQU [] ECHO  %srceDIR3%

    IF NOT [%srceDIR3%] EQU [] ECHO * Copies TO *

    IF NOT [%trgtDIR3%] EQU [] ECHO  %trgtDIR3%

    ::

    IF NOT [%srceDIR4%] EQU [] ECHO -----------------------------------------------------------------

    IF NOT [%srceDIR4%] EQU [] ECHO  %srceDIR4%

    IF NOT [%srceDIR4%] EQU [] ECHO * Copies TO *

    IF NOT [%trgtDIR4%] EQU [] ECHO  %trgtDIR4%

    ::

    IF NOT [%srceDIR5%] EQU [] ECHO -----------------------------------------------------------------

    IF NOT [%srceDIR5%] EQU [] ECHO  %srceDIR5%

    IF NOT [%srceDIR5%] EQU [] ECHO * Copies TO *

    IF NOT [%trgtDIR5%] EQU [] ECHO  %trgtDIR5%

    ::

    IF NOT [%srceDIR6%] EQU [] ECHO -----------------------------------------------------------------

    IF NOT [%srceDIR6%] EQU [] ECHO  %srceDIR6%

    IF NOT [%srceDIR6%] EQU [] ECHO * Copies TO *

    IF NOT [%trgtDIR6%] EQU [] ECHO  %trgtDIR6%

    ::

    IF NOT [%srceDIR7%] EQU [] ECHO -----------------------------------------------------------------

    IF NOT [%srceDIR7%] EQU [] ECHO  %srceDIR7%

    IF NOT [%srceDIR7%] EQU [] ECHO * Copies TO *

    IF NOT [%trgtDIR7%] EQU [] ECHO  %trgtDIR7%

    ::

    IF NOT [%srceDIR8%] EQU [] ECHO -----------------------------------------------------------------

    IF NOT [%srceDIR8%] EQU [] ECHO  %srceDIR8%

    IF NOT [%srceDIR8%] EQU [] ECHO * Copies TO *

    IF NOT [%trgtDIR8%] EQU [] ECHO  %trgtDIR8%

    ::

    IF NOT [%srceDIR9%] EQU [] ECHO -----------------------------------------------------------------

    IF NOT [%srceDIR9%] EQU [] ECHO  %srceDIR9%

    IF NOT [%srceDIR9%] EQU [] ECHO * Copies TO *

    IF NOT [%trgtDIR9%] EQU [] ECHO  %trgtDIR9%

    ::

    IF NOT [%srceDIR10%] EQU [] ECHO -----------------------------------------------------------------

    IF NOT [%srceDIR10%] EQU [] ECHO  %srceDIR10%

    IF NOT [%srceDIR10%] EQU [] ECHO * Copies TO *

    IF NOT [%trgtDIR10%] EQU [] ECHO  %trgtDIR10%

    ECHO -----------------------------------------------------------------

    ECHO.

    GOTO Again

    ::END verfyVARs

    :FileCopy

    ECHO.

    ECHO ##################################################################

    ECHO  ** Each Copy Process will Launch via A New CMD Window/Process **

    ECHO  ----------------------------------------------------------------

    ECHO  **      Note: Do NOT close the CMD windows as they will       **

    ECHO  **      automatically close when the copy is complete         **

    ECHO ##################################################################

    ECHO.

    PAUSE

    IF NOT [%srceDIR1%] EQU [] START ROBOCOPY %srceDIR1% %trgtDIR1% *.* /E /R:4 /W:5 /TEE /MT:25 /Z /ETA /LOG:%DIR1%

    IF NOT [%srceDIR2%] EQU [] START ROBOCOPY %srceDIR2% %trgtDIR2% *.* /E /R:4 /W:5 /TEE /MT:25 /Z /ETA /LOG:%DIR2%

    IF NOT [%srceDIR3%] EQU [] START ROBOCOPY %srceDIR3% %trgtDIR3% *.* /E /R:4 /W:5 /TEE /MT:25 /Z /ETA /LOG:%DIR3%

    IF NOT [%srceDIR4%] EQU [] START ROBOCOPY %srceDIR4% %trgtDIR4% *.* /E /R:4 /W:5 /TEE /MT:25 /Z /ETA /LOG:%DIR4%

    IF NOT [%srceDIR5%] EQU [] START ROBOCOPY %srceDIR5% %trgtDIR5% *.* /E /R:4 /W:5 /TEE /MT:25 /Z /ETA /LOG:%DIR5%

    IF NOT [%srceDIR6%] EQU [] START ROBOCOPY %srceDIR6% %trgtDIR6% *.* /E /R:4 /W:5 /TEE /MT:25 /Z /ETA /LOG:%DIR6%

    IF NOT [%srceDIR7%] EQU [] START ROBOCOPY %srceDIR7% %trgtDIR7% *.* /E /R:4 /W:5 /TEE /MT:25 /Z /ETA /LOG:%DIR7%

    IF NOT [%srceDIR8%] EQU [] START ROBOCOPY %srceDIR8% %trgtDIR8% *.* /E /R:4 /W:5 /TEE /MT:25 /Z /ETA /LOG:%DIR8%

    IF NOT [%srceDIR9%] EQU [] START ROBOCOPY %srceDIR9% %trgtDIR9% *.* /E /R:4 /W:5 /TEE /MT:25 /Z /ETA /LOG:%DIR9%

    IF NOT [%srceDIR10%] EQU [] START ROBOCOPY %srceDIR10% %trgtDIR10% *.* /E /R:4 /W:5 /TEE /MT:25 /Z /ETA /LOG:%DIR10%

    ECHO.

    ECHO ##################################################################

    ECHO  **         COPY PROCESS STARTED (for all valid paths)         **

    ECHO  ----------------------------------------------------------------

    ECHO  **      Note: Do NOT close the CMD windows as they will       **

    ECHO  **      automatically close when files are copied             **

    ECHO ##################################################################

    ECHO.

    ECHO.

    ECHO ##########################################################

    ECHO  **  File copy details can be found via the following  **

    ECHO  **  Robocopy Logs (Listed below)                      **

    ECHO ----------------------------------------------------------

    IF NOT [%srceDIR1%] EQU [] ECHO  -^>  %DIR1%

    IF NOT [%srceDIR2%] EQU [] ECHO  -^>  %DIR2%

    IF NOT [%srceDIR3%] EQU [] ECHO  -^>  %DIR3%

    IF NOT [%srceDIR4%] EQU [] ECHO  -^>  %DIR4%

    IF NOT [%srceDIR5%] EQU [] ECHO  -^>  %DIR5%

    IF NOT [%srceDIR6%] EQU [] ECHO  -^>  %DIR6%

    IF NOT [%srceDIR7%] EQU [] ECHO  -^>  %DIR7%

    IF NOT [%srceDIR8%] EQU [] ECHO  -^>  %DIR8%

    IF NOT [%srceDIR9%] EQU [] ECHO  -^>  %DIR9%

    IF NOT [%srceDIR10%] EQU [] ECHO  -^>  %DIR10%

    ECHO ----------------------------------------------------------

    ECHO.

    GOTO Again

    ::END FileCopy

    :LnchLgs

    ECHO.

    ECHO #################################################################

    ECHO  ** This will open all Log files via a new Notepad Window     **

    ECHO  ** NOTE: Log files are created once file copies are complete **

    ECHO #################################################################

    ECHO.

    PAUSE

    IF NOT [%srceDIR1%] EQU [] START notepad %DIR1%

    IF NOT [%srceDIR2%] EQU [] START notepad %DIR2%

    IF NOT [%srceDIR3%] EQU [] START notepad %DIR3%

    IF NOT [%srceDIR4%] EQU [] START notepad %DIR4%

    IF NOT [%srceDIR5%] EQU [] START notepad %DIR5%

    IF NOT [%srceDIR6%] EQU [] START notepad %DIR6%

    IF NOT [%srceDIR7%] EQU [] START notepad %DIR7%

    IF NOT [%srceDIR8%] EQU [] START notepad %DIR8%

    IF NOT [%srceDIR9%] EQU [] START notepad %DIR9%

    IF NOT [%srceDIR10%] EQU [] START notepad %DIR10%

    ECHO.

    GOTO Again

    ::END LnchLgs

    :Again

    PAUSE

    CLS

    GOTO Loop

    :End

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-03-06T19:10:20+00:00

    Unfortuantley freinds compuyer is other end of UK and I don't have remote access at present.

    THink we'll just have to stick with copy and paste for now.

    THanks for your input

    Trevor

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2012-03-06T10:07:07+00:00

    Thansk for the feedbback.  Not sure that this will solve the problem as depending on what other decices are plugged in to the usb hub drive letters will change.

    Unless theres a way to assign a drive letter to a specific USB port?

    Trevor

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2012-03-06T07:30:51+00:00

    Hi,

    I would suggest you to change the Drive letter of the USB to “K” before copying the files.

    So that when the USB drive is plugged to other computer will read as “K”

    Follow the link mentioned below, perform the steps and check if it helps.

    Change, add, or remove a drive letter

    http://windows.microsoft.com/en-US/windows7/Change-add-or-remove-a-drive-letter

    Let us know if it helps.

    Was this answer helpful?

    0 comments No comments