.bat file for copy-pasting folder in Windows XP - windows

I need to copy-paste a folder (files + subfolders) into a BackUpfolder. I also need to append the time into the BackUp folder name. xcopy command is letting me copy only files. Your help would be appreciated.
Source Folder = "C:\Documents and Settings.....\Project" (has many files + subfolders)
Target Folder = "C:\Backup-Date/time of backup" Eg Bacup:May 16 2011 12:30 AM
I plan to run this bat file through Scheduler. Thanks!

XCOPY
Copy files and/or directory trees to another folder. XCOPY is similar to the COPY command except that it has additional switches to specify both the source and destination in detail.
XCOPY is particularly useful when copying files from CDROM to a hard drive, as it will automatically remove the read-only attribute.
Syntax
XCOPY source [destination] [options]
/S Copy folders and subfolders
/E Copy folders and subfolders, including Empty folders.
May be used to modify /T.
/H Copy hidden and system files and folders (default=N)
Key
source : Pathname for the file(s) to be copied.
destination : Pathname for the new file(s).
There are several options you can look at :http://ss64.com/nt/xcopy.html
Soruce: http://ss64.com/nt/xcopy.html

I think reading the documentation of xcopy would go a long way.

Related

How to batch copy a list of folders and its file contents from a text file into a new folder in windows

I have a folder with approximately 7000 subfolders. I am interested in copying 1500 of those subfolders and their file contents into a new folder.
The closest I have got is copying the subfolders file contents into a new Target folder. However, the file contents are not copied over within their resepective subfolder making the batch copy useless to me.
Here is what I have tried.
CD E:\Source_Folder
FOR /F "delims=" %%N in (List.txt) do COPY "%%N" "Target_Folder"
I have tried XCOPY, ROBOCOPY, as well and all give me the same output of individual files in my target folder. I am looking for the subfolders with their contents to be copied into my new target folder.
Any help would be much appreciated. Thanks!
Just a try: rsync in linux does have the option to take the file-list to be synced from a file. Maybe robocopy (which is the windows-pendant) has the same capability, then you need one robocopy x y z only.
-edit: robocopy can'r read from a file, but if you search for 'robocopy reading from list' you get a lot of short scripts.

Copying 1 file into multiple subfolders

I am a novice. I am trying to copy 1 file into multiple subfolders within windows file explorer. I have successfully copied 1 file into multiple folders within a specified drive using the template below using the CMD prompt.
for /D %a in ("path-to-folder*.*") do xcopy /y /d "Path-to-file\file.FileExt" "%a"
This successfully copies one file to all folders within a specified folder.
Unfortunately I need to copy 1 file into multiple subfolders within a file. I will try to explain as best I can below:
I need an Excel file to copy to all Facility Subfolders within a Facility Folder under Folder1.
File.xls --> Folder 1 --> Facility Folder --> Facility Subfolder
Does that make sense? I need to do this frequently and copy and pasting the excel file to all facility subfolders is time consuming.
Thank you for any assistance!
D

Copy all desktop.ini using xcopy

I use this command in order to copy all .ini files (with recursion):
xcopy c:\folder1\folder1A\*.ini c:\mybackup /sy It doesn't copy any file.
There exist desktop.ini files (including comments) within folders and subfolders of folder1A that I want to get a copy of with recursion.
I have tried running CMD as administrator, but it tells 0 File(s) copied. How could I get this to work?
Add the /h option:
/H Copies hidden and system files also. (more info)
This works:
xcopy c:\folder1\folder1A\*.ini c:\mybackup /syh
Thanks to Marged's comment mentioning this question.

Move directories with wildcards into another directory with robocopy or move in cmd

I read Windows batch command to move all folders in a directory with exceptions but this did not work with wildcards. I want to move all folders (!), not files, inside a folder into 2010.
I have 2010-01, 2010-02, 2010-03, ... but also 2011-01, ...
How can I move (!) all folders including files inside 2010. For files this works perfectly with
move *2010* 2010
where the second 2010 is the destination folder.
Probably robocopy is the right tool for you. You can use the following command to move all directories and files from the directory source_dir into target_dir, preserving the directory structure:
c:\robocopy source_dir target_dir /S /MOVE

What should I write into the .bat file for it to find all files in folder and replace them with file from another?

What should I write into the .bat file for it to find all files with same names in folder (and it's sub folders) and replace them with file from another file (from another folder)?
Is there any fast way if we have 1 000 000 folders with nearely 10 000 files for replacement?
Try
XCOPY /U
/U will make it only copy files from the source to files in the destination, it won't copy any files that do not already exist (which is what I think you are asking for).
To copy files with the same names from c:\weebles to c:\wobble you would do
XCOPY c:\weebles c:\wobble /U /Y
Specify /U to only copy files that already exist in the destination
Specify /Y to copy without asking your permission to overwrite each file (will get tedious really quick).
For more info, open a command prompt and type
help xcopy
IMPORTANT: Before you try this (or a variant) do either:
A backup of your destination folder
A test on some folders that don't matter
Would be a shame to go all gung ho, start the copy then regret it! :-)

Resources