Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Batch file to copy files from one folder to another folder

02 Mar 2018   #1
gaanalola

Microsoft Windows 7 Ultimate 64-bit 7601 Multiprocessor Free Service Pack 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 System SpecsSystem Spec
.
02 Mar 2018   #2
samuria

win 8 32 bit
 
 

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 System SpecsSystem Spec
03 Mar 2018   #3
Golden
Microsoft MVP

Windows 7 Ult. x64
 
 

Use a robocpy .bat file in a scheduled task.
My System SpecsSystem Spec
.

05 Mar 2018   #4
gaanalola

Microsoft Windows 7 Ultimate 64-bit 7601 Multiprocessor Free Service Pack 1
 
 

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.

Quote   Quote: Originally Posted by Golden View Post
Use a robocpy .bat file in a scheduled task.
My System SpecsSystem Spec
05 Mar 2018   #5
samuria

win 8 32 bit
 
 

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 System SpecsSystem Spec
08 Mar 2018   #6
TechnoMage2016

Windows 7 Ultimate, SP1, x86
 
 

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 System SpecsSystem Spec
08 Mar 2018   #7
mrjimphelps

Linux Mint 18.2 xfce 64-bit (VMWare host) / Windows 8.1 Pro 32-bit (VMWare guest)
 
 

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 System SpecsSystem Spec
13 Mar 2018   #8
Golden
Microsoft MVP

Windows 7 Ult. x64
 
 

Quote   Quote: Originally Posted by TechnoMage2016 View Post
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 System SpecsSystem Spec
15 Mar 2018   #9
gaanalola

Microsoft Windows 7 Ultimate 64-bit 7601 Multiprocessor Free Service Pack 1
 
 

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

Quote   Quote: Originally Posted by samuria View Post
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 System SpecsSystem Spec
15 Mar 2018   #10
gaanalola

Microsoft Windows 7 Ultimate 64-bit 7601 Multiprocessor Free Service Pack 1
 
 

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.:)

Quote   Quote: Originally Posted by samuria View Post
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 System SpecsSystem Spec
Reply

 Batch file to copy files from one folder to another folder




Thread Tools




Similar help and support threads
Thread Forum
search multiple files, copy+paste to new folder (batch file software?)
I am a complete newbie when it comes to batch files and batch file software, so apologies in advance. I've done some research on Google etc but I seem to just be getting more and more confused trying to use various different scripts and programs and reading different info on various websites. ...
General Discussion
Move files from original folder to existing folders - w batch file?
My files have a format of "ID_date_time.d7d Ex: 11111-5_2013_10_07_142149.d7d The ID is 1111-5 and was tested 10/7/2013 at 2:21:49 PM and the file extension is always .d7d The local files are automatically saved here by the program generating the data: C:\Local\Data I want them copied...
General Discussion
Custom batch file that copies font files to another folder?
I just downloaded all of the Google Web Fonts and they were each downloaded into their respected folders, so instead of clicking on folder after folder and right clicking after right clicking and finally installing each and every font; How can I create a command prompt (batch) file so the prompt...
General Discussion
Need a Batch File to Copy to a Custom Dest Folder
I need help with a batch file to copy the contents of my source dir to the destination dir that is to be created with that days date using xcopy or robocopy. Any help is appreciated!
Network & Sharing
Batch file for moving files to folder?
Hello, Wanted to see if any one here wouldn't mind writing a batch file or script that would move multiple files to a target folder. Here are the specifics: HDD1 Contains Folders A,B,C,etc... Folder A contains Folder A1 which contains File A2 Folder B contains Folder B1 which contains File B2...
General Discussion


Our Sites

Site Links

About Us

Find 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 12:15.
Twitter Facebook Google+ Seven Forums iOS App Seven Forums Android App