Autocopy Batch file from usb drive to hhd ?


  1. Posts : 55
    Windows 64bit
       #1

    Autocopy Batch file from usb drive to hhd ?


    Hello,
    I need a batch file which auto copy files from any USB drive when it connected to a folder in the hard disk .
      My Computer


  2. Posts : 6,285
    Windows 10 Pro X64
       #2

    The problem trying to do that is the USB drive may have different drive letters assigned at different times so the batch file would need to be able to find the USB drive in order to copy from it.

    You may be able to do this with PowerShell or VB Script but I don't know how to do so.
      My Computer


  3. Posts : 55
    Windows 64bit
    Thread Starter
       #3

    Ztruker said:
    The problem trying to do that is the USB drive may have different drive letters assigned at different times so the batch file would need to be able to find the USB drive in order to copy from it.

    You may be able to do this with PowerShell or VB Script but I don't know how to do so.
    I didn't find the right forum to post my question, so I posted it here
    Every time I have a problem I find the solution here .
      My Computer


  4. Posts : 55
    Windows 64bit
    Thread Starter
       #4

    any one else can help me ?
      My Computer


  5. Posts : 10,485
    W7 Pro SP1 64bit
       #5

    You should (IMO) clarify what you mean by auto-copy.

    Auto-copy could mean:
    ...attach USB drive
    ...and the files of interest automatically copy to the folder of interest on the hard disk.

    OR

    Auto-copy could mean:
    ...attach USB drive
    ...and you manually start the batch file
    ...that copies the files of interest automatically copy to the folder of interest on the hard disk.

    Which is it?

    Maybe your batch file could search thru each drive letter - looking for a certain file name. Once that file name is found, then you know that the USB drive of interest is attached and then copy the files.

    Code:
    IF EXIST D:\ID-FILE.txt copy D:\*.* C:\folder\*.*
    IF EXIST E:\ID-FILE.txt copy E:\*.* C:\folder\*.*
    IF EXIST F:\ID-FILE.txt copy F:\*.* C:\folder\*.*
    I'm sure that there is a pretty way to enumerate the possible drive letters.
    Last edited by UsernameIssues; 24 Apr 2016 at 16:11.
      My Computer


  6. Posts : 6,285
    Windows 10 Pro X64
       #6

    If you control the content of the flash drive then you could put a batch file on it that does something like the following. We'll call it FlashAutocopy.bat.

    xcopy \*.* %userprofile%\temp\autocopy\ /s/h/r/i/k/e/y /exclude FlashAutocopy.bat autorun.inf

    (add /d if you only want to copy files that do not already exist in the autocopy folder)

    xcopy \*.*says to copy all files and folders starting at the root of the flash drive.
    %userprofile%\temp\autocopysays to copy to your profile directory, temp\autocopy folder.
    /exclude FlashAutocopy.bat autorun.inf says to not copy these files.

    You could also put a autorun.inf file in the root of the flash drive with one line it it that says:

    open=
    FlashAutocopy.bat

    Then is autorun is enabled when you connect the flash drive it will automatically start FlashAutocopy.bat.
      My Computer


  7. Posts : 2,774
    Windows 7 Professional 64-bit
       #7

    If the usb drive is always put into the same usb port, you can assign a drive letter to it. I gave mine Z [for example]. To keep your cd-dvd device from entering the fray, assign it drive letter I [for example], and let your batchfile not specify drive letter I. Do you have your OS partition as C and data partition assigned drive letter D? That will keep a universal batchfile from accidentally copying from your data partition.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 02:36.
Find Us