[Solved] batch file to copy files to another location?

Is it possible to create a batch file to copy a folder to another location everytime I login, or when the folder is updated?

It could be written in VB or Java as well if not an easy solution.

Any ideas?

Enquirer: Elliott

||

Solution #1:

Two approaches:

  • When you login: you can to create a copy_my_files.bat file into your All Programs > Startup folder with this content (its a plain text document):

    • xcopy c:folder*.* d:another_folder.

    Use xcopy c:folder*.* d:another_folder. /Y to overwrite the file without any prompt.

  • Everytime a folder changes: if you can to use C#, you can to create a program using FileSystemWatcher

Respondent: Rubens Farias

Solution #2:

@echo off
copy con d:*.*
xcopy d:*.* e:*.*
pause
Respondent: Mohammed Salem

Solution #3:

Open Notepad.

Type the following lines into it (obviously replace the folders with your ones)

@echo off
rem you could also remove the line above, because it might help you to see what happens

rem /i option is needed to avoid the batch file asking you whether destination folder is a file or a folder
rem /e option is needed to copy also all folders and subfolders
xcopy "c:New Folder" "c:Copy of New Folder" /i /e

Save the file as backup.bat (not .txt)

Double click on the file to run it. It will backup the folder and all its contents files/subfolders.

Now if you want the batch file to be run everytime you login in Windows, you should place it in Windows Startup menu. You find it under: Start > All Program > Startup
To place the batch file in there either drag it into the Startup menu or RIGH click on the Windows START button and select Explore, go in Programs > Startup, and copy the batch file into there.

To run the batch file everytime the folder is updated you need an application, it can not be done with just a batch file.

Respondent: Marco Demaio

Solution #4:

Batch file to copy folder is easy.

xcopy /Y C:Source*.* C:NewFolder

Save the above as a batch file, and get Windows to run it on start up.

To do the same thing when folder is updated is trickier, you’ll need a program that monitors the folder every x time and check for changes. You can write the program in VB/Java/whatever then schedule it to run every 30mins.

Respondent: Robo

Solution #5:

It’s easy to copy a folder in a batch file.

 @echo off
 set src_folder = c:whatever*.*
 set dst_folder = c:foo
 xcopy /S/E/U %src_folder% %dst_folder%

And you can add that batch file to your Windows login script pretty easily (assuming you have admin rights on the machine). Just go to the “User Manager” control panel, choose properties for your user, choose profile and set a logon script.

How you get to the user manager control panel depends on which version of Windows you run. But right clicking on My Computer and choosing manage and then choosing Local users and groups works for most versions.

The only sticky bit is “when the folder is updated”. This sounds like a folder watcher, which you can’t do in a batch file, but you can do pretty easily with .NET.

Respondent: John Knoeller

Solution #6:

robocopy yourfolder yourdestination /MON:0

should do it, although you may need some more options. The switch at the end will re-run robocopy if more than 0 changes are seen.

Respondent: Joey

Solution #7:

@echo off
cls
echo press any key to continue backup !
pause
xcopy c:usersfile*.* e:ackup*.* /s /e
echo backup complete
pause


file = name of file your wanting to copy

backup = where u want the file to be moved to

Hope this helps

Respondent: ANONYMOUS

Solution #8:

@echo off
xcopy ...

Replace ... with the appropriate xcopy arguments to copy what you want copied.

Respondent: Anon.

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.