How would I go about making a batch file that empties a backup folder on my PC and then copies over the data on my USB to the folder. And then each evening my files would be backed up by simple clicking on the file. I don't have a very big grasp on how batch files work. Could somebody point me in the right direction as to what this would look like?
ROBOCOPY f:\myusb c:\myfolder /mir
It will copy from source (the usb) to target (the hd) from/to indicated folders all the new and updated files, ignore and leave all the non changed files and remove from target all the files not present in source.
XCOPY /s "C:\folder\" "F:\"
30sec on startpage/google
Will not work on W8 it seems thought
EDIT: for Win8:
ROBOCOPY /E C:\folder\ F:\folder, /E
is for copying all subfolder in the folder.
Related
Here it is:
xcopy /s %systemdrive%\users\%username%\Desktop\Program\folderx %appdata%\.home\saves
but that is only if I copy the folder to the desktop, is there a way where I can simply click the batch from anywhere i.e. D Drive, H Drive, My documents, on any windows machine and it copies to the .home\saves
Edit:
Sorry was a bit vague
Folderx is in another Folder on the desktop called "program". The batch file is also in the folder entitled " program" on the desktop. When I double click the batch file, it copies the " Folderx" and its subdirectory to %appdata%.home\saves. But lets say I have it on my flash, and someone copies it to their C drive. Is there a universal way for the batch file to still copy folderx, regardless of where the "program" folder is?
Also let me know.
The question is unclear, but here goes. This will copy folderx if it exists in the same directory as the batchfile.
xcopy /S .\folderx %appdata%\.home\saves
This will copy ALL directories and files from the where the batch file exists.
xcopy /S .\* %appdata%\.home\saves
If you are a bit more specific with the question, I can add the options
I want to use a batch file to synchronize 2 folders on Windows, and I'm using the xcopy command like this
xcopy /s /d <Original Folder> <Destination Folder>
It's working perfectly because I just want to overwrite only the modified ones, but I have 1 tiny problem, when I delete a file from the original folder, that file remains in the destination folder when i run the batch file, breaking the synching I want to achieve... I think this can't be done with xcopy, but I don't know which command I should use in case I delete a file in the original folder.
EDIT: This programs is for people who don't understant a lot of PC's so i don't want to install anything in their pc's. Just want a plain batch file to keep the 2 folders synchronized
SOLUTION: Thanks to Kuba Wyrostek I got to this command
robocopy <Original Folder> <Destination Folder> /e /purge
Thank you all for your time
xcopy has no such option. Your alternatives are:
rsync - http://rsync.samba.org
robocopy - http://technet.microsoft.com/en-us/library/cc733145.aspx
To refine your answer, you can simply do:
robocopy <Original Folder> <Destination Folder> /mir
/mir mirrors a directory tree (equivalent to /e plus /purge).
The XCOPY command for copying the updates from one folder to another is as follows:
C:\> XCOPY C:/SOURCE D:/DESTINATION /E /D /C /Y
The flags used in the above example have the following meanings:
/E causes all folders and sub-folders to be copied
/D causes a DATE comparison to be made, only copying items that are newer than the DESTINATION item. If the DESTINATION is older, or does not contain the file, then it will be copied.
/C tells XCOPY to continue if it encounters an error - typically errors occur with read-only files, or files that have protected permissions
/Y tells XCOPY to suppress prompting you for confirmation, which is necessary if you intend to create an automation script or scheduled task
I know this is old, but I have a question. Can this not be done with the correct xcopy commands.
Folder 1: c:\workingFolder\"contents here"
Folder 2: d:\workingFolderSync\"contents here"
Batch file below
xcopy "c:\workingFolder\*.*" "d:\workingFolderSync\" /i /s /d /y
xcopy "d:\workingFolderSync\*.*" "c:\workingFolder\" /i /s /d /y
pause
( I usually remove the pause after i test and know the batch works. )
But this will only copy contents from the folder to the other if its newer.
Then it looks in the destination folder and copies contents from destination back to source if it is newer. This reproduces what syncing does, except for the in real time monitoring of modified files. Creating a proper task schedule can actually implement running this command at specific times to almost perfectly reproduce syncing. You can also run this before modification on a machine and after modification on a machine. Even doing the same thing on a second machine if your using a network drive to sync.
Your method will have two main problems:
Files deleted from one folder will be reinstated by the copy left in the other folder the next time you run your xcopy
Renaming files can cause chaotic results.
I would like to know how to copy a folder to another folder in a batch file.
I would like stuff with the same name to be overwritten.
Thanks.
Unless I'm missing something, the easiest way is with xcopy (provided you actually mean .bat files on Windows):
xcopy <SOURCE> <DEST> /e /d /y /h /r /c
To explain those flags:
/e: Include directories and sub directories even if empty
/d: Only copy files which have changed on SOURCE more recently than DEST
/y: Suppress prompts
/h: Also copy hidden and system files
/r: Override read-only files (e.g. ignore Read Only flag)
/c: Continue even if there are errors
Source: My standard backup script, been running every day for 6 years.
or take a look at ROBOCOPY en.wikipedia.org/wiki/Robocopy
I have a folder containing many other sub-folders. I am trying to write a batch file which will copy some of the folders to another place on my hard disk. I am using xcopy for this. The folder structure is as shown below:
FolderB1
FolderB2
FolderB22
File1.txt
File2.txt
File3.txt
I have some .txt files inside FolderB1, along with FolderB2 and FolderB22. I want to copy FolderB2 and FolderB22 and skip .txt files contained in Folder B1
I tried using /EXCLUDE: param of xcopy command, but it is not able to perform this operation. It does not work if I specify the exclusion as \FolderB1\*.txt or something of this sort.
The number of main folders is not known. It can be anything. Also, there is no fix pattern for names of .txt files. Have checked this question too, but did not help.
Also, I want to avoid using del command, since copying all and deleting again would consume time.
Can this be achieved using Robocopy? Exactly similar question is raised here.
Any pointers would be useful. Thanks in advance.
To clarify, I asume you mean to exclude all .txt files in FolderB1, but not exclude .txt located elsewhere.
You can do that with robocopy in two steps. First copy all files except any .txt. And in the second step copy only .txt files, but exclude FolderB1.
robocopy c:\source c:\destination /s /xf *.txt
robocopy c:\source c:\destination *.txt /s /xd c:\source\FolderB1
I have looked on a lot of the questions here and I dont see really what I need. I am trying to create a batch file that pulls 6 log files from 2 different places.
The first place its pulling them from is the C:\
Second place is C:\COSS\CossEnterpriseSuite\Exes\
I am wanting it to pull the *.log files and for it to put them in a folder called ERRORLOG on the C:.
If anyone could help me with this it would be great the stress level is raising.
Try this:
xcopy /y C:\*.log C:\ERRORLOG
xcopy /y C:\COSS\CossEnterpriseSuite\Exes\*.log C:\ERRORLOG
This will wildcard-copy anything that ends with the .log extension from the directories you mentioned, dropping them in the C:\ERRORLOG directory. The /y switch makes sure it doesn't prompt before overwriting existing files.