What is the windows command prompt command to copy files?
I need to move a file from location A to location B. Also if the folder for location B doesn't' exists I want to have it created.
I need this to be a command line so I can automate it.
The version of Windows is XP.
The command
xcopy
is what you are looking for. Example:The command above will copy source to destination, files and directories (including empty ones), will not stop on error, will copy hidden and system files, will overwrite read only files, will preserve attributes and ownership/ACL information, and will suppress the prompting for overwrite existing destination files.
For more info type
xcopy /?
and your command line.Use md to create the folder (it's ok if it already exists)
Use copy or move for files, and xcopy for folders
Use ROBOCOPY if you're creating backup scripts. xcopy has been deprecated and will likely be phased out of use in the near future. robocopy can do everything xcopy can. It is also more flexible and reliable. Creating scripts with robocopy will future-proof them.
Use robocopy to easily copy folders. The robocopy command replaces the xcopy command. It can quickly copy entire folders without having to worry about defining the contents. For example, to copy all of the contents of the C:\tools directory to the new folder D:\backup\tools, enter the following:
The /e modifier tells robocopy to include all subdirectories. This includes empty folders. robocopy will automatically copy hidden and system files. It will create new directories if they don't exist at the target location.
Mirror a directory. Mirroring a directory is great for making backups. The mirror option of robocopy will copy all of the contents from the source to the destination. It will then delete anything at the destination that doesn't exist at the source. This ensures that your backup only has the latest versions of your files. For example, to mirror C:\Users\My Documents to D:\backup\My Documents, enter the following:[4]
This function will preserve all permissions of the original files.
Enable restarting. You may want to include the ability to restart the process in case the connection is severed mid-copy.
Log the copying process. robocopy allows you to create a log file. This can help you pinpoint problems or generate an archive of what's been copied.
The /log+ modifier will append the existing log file instead of overwriting it. If you'd prefer to just overwrite the old log file, use /log:.txt.
In a batch file:
if not exists
checks the parameter to see if it exists, but it only works on files. To check for existence of a directory, you need to look for a 'pseudo-file' called "nul" - checking for existence of this file will always return true if the directory exists.The copy line copies the file called
file
in directorylocationA
tolocationB
and names the file the same thing. If you want to rename the file at the same time, you can do that too:If you want the ability to synchronise the copy and other advanced features (ignore certain folders, only include certain wildcards) then look at
robocopy
. Included in Vista and beyond, optional (from resource kit tools) in earlier versions.xcopy will create the directory structure for you. Trick is to use the /I option and throw an asterisk at the end of the file name so xcopy thinks you're copying multiple files, otherwise it asks you if the target name is the file name you want, or the directory name you want. For example.
I'd also look at RoboCopy, but you need to get it from the resource kit as it's not in Windows until Vista.
The above command creates an additional directory level with the name of the source file. So... xcopy /I srcdir\dir1\dir2\file1.txt* destdir\dir1\dir2\file1.txt results in destdir\dir1\dir2\file1.txt\file1.txt