Batch file to copy files from one folder to another folder

Page 1 of 2 12 LastLast

  1. Posts : 5
    Microsoft Windows 7 Ultimate 64-bit 7601 Multiprocessor Free Service Pack 1
       #1

    Batch file to copy files from one folder to another folder


    Hi,

    Sorry to create a new thread if it is already exists, If my requirement has an answer already in forum please help me to find as i couldn't find yet.

    I have network storage drive in which my onsite team will place files regularly, We need to move those files from one folder to another folder. for this we are using a bat file now. The bat file has below code,
    Code:
    Move C:\Media\All_Files\All_Completed\*.*  D:\Pri_Files\Desk2\
    The problem with this code is,

    • We need to run it manually for every time.
    • It is copying every file from source folder to destination folder
    • It is creating duplicate files in destination folder
    • need to check manually for new files every time

    Can anyone suggest me a good way to run this job automatically and copies only new files from that source file to destination.

    It would be great that we can make the script to run automatically for every 5 or 10 minutes to check for new files in source folder.

    The source folder has also sub folders sometimes, but we just need to copy only files(PDF) from that folder.

    If there are any ongoing copying files, the job should run for completed files or after copying completed.

    Please help me to solve this, Thanks in advance.
      My Computer


  2. Posts : 3,783
    win 8 32 bit
       #2

    Robocopy whichh is buit into windows jsuttype robocopy at a cmd promt has more options is fast only copies changed built for servers you can get a free gui to make life simpler as it writes the code for you Utility Spotlight: Robocopy GUI.

    You could write the code then put in a wait 10mins then start again
      My Computer


  3. Posts : 19,383
    Windows 10 Pro x64 ; Xubuntu x64
       #3

    Use a robocpy .bat file in a scheduled task.
      My Computer


  4. Posts : 5
    Microsoft Windows 7 Ultimate 64-bit 7601 Multiprocessor Free Service Pack 1
    Thread Starter
       #4

    Hi Golden,

    Before posting this thread, I came to this forum because of your tutorial on RoboCopy. If you don't mind can you please provide code for my requirement? Thanks in advance.

    Golden said:
    Use a robocpy .bat file in a scheduled task.
      My Computer


  5. Posts : 3,783
    win 8 32 bit
       #5

    robocopy C:\Media\All_Files\All_Completed\ D:\Pri_Files\Desk2\ /MIR /FFT /Z /XA:H /W:5

    Explanation of the switches used:

    • /MIR specifies that Robocopy should mirror the source directory and the destination directory. Note that this will delete files at the destination if they were deleted at the source.
    • /FFT uses fat file timing instead of NTFS. This means the granularity is a bit less precise. For across-network share operations this seems to be much more reliable - just don't rely on the file timings to be completely precise to the second.
    • /Z ensures Robocopy can resume the transfer of a large file in mid-file instead of restarting.
    • /XA:H makes Robocopy ignore hidden files, usually these will be system files that we're not interested in.
    • /W:5 reduces the wait time between failures to 5 seconds instead of the 30 second default.



    A lot simpler and foolproof way is to install google drive or onedrive save file to the folder login on both pc to the drive with same name as you save a file it will apear on th eother without you doing anything same if you change a file
      My Computer


  6. Posts : 714
    Win 7 Pro, SP1, x86, Win-11/Pro/64
       #6

    If I installed a new program every time I wanted to do something, I'd have to buy a larger hard drive just to hole them all.

    I do pretty much what the OP wants to do, using what's already built into Windows (all versions).

    XCOPY is a very powerful copy command and it's been around since DOS days. I used it then and I use it now. I have 12 computers and xcopy is on every one of them, so it's there any time I need it to write a quick batch file or to do a One-Time copy.

    I do all my data backups to flash drives, external 1TB hard drive, etc., using a simple batch file and XCOPY.

    For instance, to backup everything in "My Documents" folder to a like folder on my External Hard drive:

    XCOPY /D /S /C /I /H /R /K /Y /J "C:\Documents and Settings\Joe\Documents\*.*" "E:\Documents\My Documents"

    Xcopy is one of the most versatile commands in the DOS library. Getting to know it and how to use it
    can save you a lot of time and energy, now and in the future. Using the various switches after the command, allows you to customize the copy operation to do exactly what you want it to do.

    You can copy the following and paste it into Wordpad and print it out for future use:

    Copies files and directory trees.

    XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
    [/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]
    [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z] [/B]
    [/EXCLUDE:file1[+file2][+file3]...]

    source Specifies the file(s) to copy.
    destination Specifies the location and/or name of new files.
    /A Copies only files with the archive attribute set,
    doesn't change the attribute.
    /M Copies only files with the archive attribute set,
    turns off the archive attribute.
    /D:m-d-y Copies files changed on or after the specified date.
    If no date is given, copies only those files whose
    source time is newer than the destination time.
    /EXCLUDE:file1[+file2][+file3]...
    Specifies a list of files containing strings. Each string
    should be in a separate line in the files. When any of the
    strings match any part of the absolute path of the file to be
    copied, that file will be excluded from being copied. For
    example, specifying a string like \obj\ or .obj will exclude
    all files underneath the directory obj or all files with the
    .obj extension respectively.
    /P Prompts you before creating each destination file.
    /S Copies directories and subdirectories except empty ones.
    /E Copies directories and subdirectories, including empty ones.
    Same as /S /E. May be used to modify /T.
    /V Verifies the size of each new file.
    /W Prompts you to press a key before copying.
    /C Continues copying even if errors occur.
    /I If destination does not exist and copying more than one file,
    assumes that destination must be a directory.
    /Q Does not display file names while copying.
    /F Displays full source and destination file names while copying.
    /L Displays files that would be copied.
    /G Allows the copying of encrypted files to destination that does
    not support encryption.
    /H Copies hidden and system files also.
    /R Overwrites read-only files.
    /T Creates directory structure, but does not copy files. Does not
    include empty directories or subdirectories. /T /E includes
    empty directories and subdirectories.
    /U Copies only files that already exist in destination.
    /K Copies attributes. Normal Xcopy will reset read-only attributes.
    /N Copies using the generated short names.
    /O Copies file ownership and ACL information.
    /X Copies file audit settings (implies /O).
    /Y Suppresses prompting to confirm you want to overwrite an
    existing destination file.
    /-Y Causes prompting to confirm you want to overwrite an
    existing destination file.
    /Z Copies networked files in restartable mode.
    /B Copies the Symbolic Link itself versus the target of the link.
    /J Copies using unbuffered I/O. Recommended for very large files.

    The switch /Y may be preset in the COPYCMD environment variable.
    This may be overridden with /-Y on the command line.

    Cheers Mate!
    TechnoMage



      My Computer


  7. Posts : 1,784
    Linux Mint 18.2 xfce 64-bit (VMWare host) / Windows 8.1 Pro 32-bit (VMWare guest)
       #7

    To use XCOPY for your situation, include the following commands in your batch file:

    XCOPY /S /M C:\Media\All_Files\All_Completed\*.* D:\Pri_Files\Desk2
    ECHO Hit CTRL-C to stop copying the files.
    sleep 300 > nul
    goto start

    -or-

    XCOPY /S /M C:\Media\All_Files\All_Completed\*.* D:\Pri_Files\Desk2
    ECHO Hit CTRL-C to stop copying the files.
    timeout /t 300 > nul
    goto start

    Explanation:
    sleep 300 > nul causes a pause of 300 seconds, or 5 minutes. The "nul" prevents anything from being echoed to the screen. You could use "timeout /t 300" rather than "sleep 300". (Sometimes one or the other won't work on your system; pick the one that works on your system.)

    goto start makes the batch file start over and run again. If you want to copy the files regularly, say every five minutes, use "sleep 300" or "timeout /t 300" followed by "goto start". It will run every five minutes if you do that.

    The ECHO command simply lets you know that you can break out of the batch file by hitting CTRL-C. That's all it does; it has no effect on the actual copy process. You can omit this command if you want to.

    /S causes XCOPY to copy all subdirectories as well as the main directory.

    /M causes XCOPY to copy all files which have been changed since the last copy. To do this, it checks the archive bit on each file. If the archive bit is turned on, it will copy the file then turn the archive bit off, effectively marking that file as copied. That file won't be copied again unless it is changed again, which will turn on the archive bit, effectively marking that file as needing to be copied.
      My Computer


  8. Posts : 19,383
    Windows 10 Pro x64 ; Xubuntu x64
       #8

    TechnoMage2016 said:
    If I installed a new program every time I wanted to do something, I'd have to buy a larger hard drive just to hole them all.

    I do pretty much what the OP wants to do, using what's already built into Windows (all versions).
    Fun fact - robocopy has been built into Windows staring with Vista. Being only a few kb in size, it hardly requires the purchase of a large hard drive. It is a far superior copying method than xcopy (it was designed to replace xcopy in fact) since it has the ability to overcome network interrupts and re-copy files, amongst a host of other things.

    In his initial post, the OP made it clear he was copying across a network, so the safest option in this case would be robocopy.
      My Computer


  9. Posts : 5
    Microsoft Windows 7 Ultimate 64-bit 7601 Multiprocessor Free Service Pack 1
    Thread Starter
       #9

    Thanks bro, however, the download link is not working now. Can you please check it?

    samuria said:
    Robocopy whichh is buit into windows jsuttype robocopy at a cmd promt has more options is fast only copies changed built for servers you can get a free gui to make life simpler as it writes the code for you Utility Spotlight: Robocopy GUI.

    You could write the code then put in a wait 10mins then start again
      My Computer


  10. Posts : 5
    Microsoft Windows 7 Ultimate 64-bit 7601 Multiprocessor Free Service Pack 1
    Thread Starter
       #10

    Thank you for trying to help me on this, But below code may not suitable for my requirement.

    My Requirement is,

    • I just need to copy only files(PDF) from that directory, Source folder has also sub folders. so don't want to touch those Folders data.
    • The copy should done for new files only that are placed recently, to eliminate duplicate files in destination folder.
    • this should be run for every 5 or 10 min to check for new files.

    Thanks in advance.:)

    samuria said:
    robocopy C:\Media\All_Files\All_Completed\ D:\Pri_Files\Desk2\ /MIR /FFT /Z /XA:H /W:5

    Explanation of the switches used:

    • /MIR specifies that Robocopy should mirror the source directory and the destination directory. Note that this will delete files at the destination if they were deleted at the source.
    • /FFT uses fat file timing instead of NTFS. This means the granularity is a bit less precise. For across-network share operations this seems to be much more reliable - just don't rely on the file timings to be completely precise to the second.
    • /Z ensures Robocopy can resume the transfer of a large file in mid-file instead of restarting.
    • /XA:H makes Robocopy ignore hidden files, usually these will be system files that we're not interested in.
    • /W:5 reduces the wait time between failures to 5 seconds instead of the 30 second default.



    A lot simpler and foolproof way is to install google drive or onedrive save file to the folder login on both pc to the drive with same name as you save a file it will apear on th eother without you doing anything same if you change a file
      My Computer


 
Page 1 of 2 12 LastLast

  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 09:06.
Find Us