🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 19 (from laksa015)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

đź“„
INDEXABLE
âś…
CRAWLED
1 day ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.1 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files
Last Crawled2026-04-05 02:25:09 (1 day ago)
First Indexed2015-06-12 12:27:08 (10 years ago)
HTTP Status Code200
Meta TitleWhat is the windows command line command to copy files? - Server Fault
Meta Descriptionnull
Meta Canonicalnull
Boilerpipe Text
This question shows research effort; it is useful and clear 45 Save this question. Show activity on this post. 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. asked May 5, 2009 at 12:50 1 This answer is useful 55 Save this answer. Show activity on this post. The command xcopy is what you are looking for. Example: xcopy source destination /E /C /H /R /K /O /Y 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. /E Copies directories and subdirectories, including empty ones. Same as /S /E. May be used to modify /T. /C Continues copying even if errors occur. /H Copies hidden and system files also. /R Overwrites read-only files. /K Copies attributes. Normal Xcopy will reset read-only attributes. /O Copies file ownership and ACL information. /Y Suppresses prompting to confirm you want to overwrite an existing destination file. For more info type xcopy /? and your command line. KCD 978 3 gold badges 13 silver badges 24 bronze badges answered May 5, 2009 at 13:21 5 This answer is useful 10 Save this answer. Show activity on this post. Use md to create the folder (it's ok if it already exists) Use copy or move for files, and xcopy for folders answered May 5, 2009 at 12:52 3 This answer is useful 5 Save this answer. Show activity on this post. 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: robocopy C:\tools D:\backup\tools /e 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] robocopy "C:\Users\My Documents" "D:\backup\My Documents" /mir 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. robocopy "C:\Users\My Documents" "D:\backup\My Documents" /z 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. robocopy "C:\Users\My Documents" "D:\backup\My Documents" /log+:<filename>.txt 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. answered Nov 22, 2015 at 21:39 This answer is useful 3 Save this answer. Show activity on this post. In a batch file: if not exists locationB\nul mkdir locationB copy locationA\file locationB 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 directory locationA to locationB and names the file the same thing. If you want to rename the file at the same time, you can do that too: copy locationA\file locationB\newfilename answered May 5, 2009 at 13:21 This answer is useful 2 Save this answer. Show activity on this post. 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. answered May 5, 2009 at 13:51 1 This answer is useful 0 Save this answer. Show activity on this post. 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. xcopy /I c:\<SourceDir>\<SourceFile> c:\<TargetDirThatDoesNOTExist> I'd also look at RoboCopy, but you need to get it from the resource kit as it's not in Windows until Vista. answered May 5, 2009 at 13:21 This answer is useful -1 Save this answer. Show activity on this post. 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 answered Jun 10, 2015 at 15:25 1 You must log in to answer this question. Start asking to get answers Find the answer to your question by asking. Ask question Explore related questions See similar questions with these tags.
Markdown
# ![site logo](https://stackoverflow.com/Content/Img/SE-logo75.png) By clicking “Sign up”, you agree to our [terms of service](https://serverfault.com/legal/terms-of-service/public) and acknowledge you have read our [privacy policy](https://serverfault.com/legal/privacy-policy). # OR Already have an account? [Log in](https://serverfault.com/users/login) [Skip to main content](https://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files#content) #### Stack Exchange Network Stack Exchange network consists of 183 Q\&A communities including [Stack Overflow](https://stackoverflow.com/), the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. [Visit Stack Exchange](https://stackexchange.com/) 1. - [Tour Start here for a quick overview of the site](https://serverfault.com/tour) - [Help Center Detailed answers to any questions you might have](https://serverfault.com/help) - [Meta Discuss the workings and policies of this site](https://meta.serverfault.com/) - [About Us Learn more about Stack Overflow the company, and our products](https://stackoverflow.co/) 2. ### [current community](https://serverfault.com/) - [Server Fault](https://serverfault.com/) [help](https://serverfault.com/help) [chat](https://chat.stackexchange.com/?tab=site&host=serverfault.com) - [Meta Server Fault](https://meta.serverfault.com/) ### your communities [Sign up](https://serverfault.com/users/signup?ssrc=site_switcher&returnurl=https%3A%2F%2Fserverfault.com%2Fquestions%2F4639%2Fwhat-is-the-windows-command-line-command-to-copy-files) or [log in](https://serverfault.com/users/login?ssrc=site_switcher&returnurl=https%3A%2F%2Fserverfault.com%2Fquestions%2F4639%2Fwhat-is-the-windows-command-line-command-to-copy-files) to customize your list. ### [more stack exchange communities](https://stackexchange.com/sites) [company blog](https://stackoverflow.blog/) 3. [Log in](https://serverfault.com/users/login?ssrc=head&returnurl=https%3A%2F%2Fserverfault.com%2Fquestions%2F4639%2Fwhat-is-the-windows-command-line-command-to-copy-files) 4. [Sign up](https://serverfault.com/users/signup?ssrc=head&returnurl=https%3A%2F%2Fserverfault.com%2Fquestions%2F4639%2Fwhat-is-the-windows-command-line-command-to-copy-files) [![Server Fault](https://serverfault.com/Content/Sites/serverfault/Img/logo.svg?v=43f5b6d5f65b)](https://serverfault.com/) 1. 1. [Home](https://serverfault.com/) 2. [Questions](https://serverfault.com/questions) 3. [Unanswered](https://serverfault.com/unanswered) 4. [AI Assist](https://stackoverflow.com/ai-assist) 5. [Tags](https://serverfault.com/tags) 6. [Chat](https://chat.stackexchange.com/) 7. [Users](https://serverfault.com/users) 8. [Companies](https://stackoverflow.com/jobs/companies?so_medium=serverfault&so_source=SiteNav) 2. Stack Internal Stack Overflow for Teams is now called **Stack Internal**. Bring the best of human thought and AI automation together at your work. [Try for free](https://stackoverflowteams.com/teams/create/free/?utm_medium=referral&utm_source=serverfault-community&utm_campaign=side-bar&utm_content=explore-teams) [Learn more](https://stackoverflow.co/internal/?utm_medium=referral&utm_source=serverfault-community&utm_campaign=side-bar&utm_content=explore-teams) 3. [Stack Internal]() 4. Bring the best of human thought and AI automation together at your work. [Learn more](https://stackoverflow.co/internal/?utm_medium=referral&utm_source=serverfault-community&utm_campaign=side-bar&utm_content=explore-teams-compact) **Stack Internal** Knowledge at work Bring the best of human thought and AI automation together at your work. [Explore Stack Internal](https://stackoverflow.co/internal/?utm_medium=referral&utm_source=serverfault-community&utm_campaign=side-bar&utm_content=explore-teams-compact-popover) # [What is the windows command line command to copy files?](https://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files) [Ask Question](https://serverfault.com/questions/ask) Asked 16 years, 11 months ago Modified [8 years ago](https://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files?lastactivity "2018-03-29 07:59:04Z") Viewed 274k times This question shows research effort; it is useful and clear 45 Save this question. Show activity on this post. 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. - [windows](https://serverfault.com/questions/tagged/windows "show questions tagged 'windows'") - [command-line-interface](https://serverfault.com/questions/tagged/command-line-interface "show questions tagged 'command-line-interface'") - [copy](https://serverfault.com/questions/tagged/copy "show questions tagged 'copy'") [Share](https://serverfault.com/q/4639 "Short permalink to this question") Share a link to this question Copy link [CC BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/ "The current license for this post: CC BY-SA 2.5") [Improve this question](https://serverfault.com/posts/4639/edit) Follow Follow this question to receive notifications asked May 5, 2009 at 12:50 [![David Basarab's user avatar](https://www.gravatar.com/avatar/200cc24cc0555d1c6bd14b5a7fe8f852?s=64&d=identicon&r=PG)](https://serverfault.com/users/823/david-basarab) [David Basarab](https://serverfault.com/users/823/david-basarab) 1,19755 gold badges1616 silver badges2020 bronze badges 1 - 1 `robocopy` works great too Nixphoe – [Nixphoe](https://serverfault.com/users/27920/nixphoe "4,622 reputation") 2011-08-08 01:06:32 +00:00 [Commented Aug 8, 2011 at 1:06](https://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files#comment284036_4639) [Add a comment](https://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files "Use comments to ask for more information or suggest improvements. Avoid answering questions in comments.") \| ## 7 Answers 7 Sorted by: [Reset to default](https://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files?answertab=scoredesc#tab-top) This answer is useful 55 Save this answer. Show activity on this post. The command `xcopy` is what you are looking for. Example: ``` xcopy source destination /E /C /H /R /K /O /Y ``` 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. ``` /E Copies directories and subdirectories, including empty ones. Same as /S /E. May be used to modify /T. /C Continues copying even if errors occur. /H Copies hidden and system files also. /R Overwrites read-only files. /K Copies attributes. Normal Xcopy will reset read-only attributes. /O Copies file ownership and ACL information. /Y Suppresses prompting to confirm you want to overwrite an existing destination file. ``` For more info type `xcopy /?` and your command line. [Share](https://serverfault.com/a/4669 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://serverfault.com/posts/4669/edit) Follow Follow this answer to receive notifications [edited Jun 25, 2015 at 23:39](https://serverfault.com/posts/4669/revisions "show all edits to this post") [![KCD's user avatar](https://www.gravatar.com/avatar/22de692b5c4bba0665322370e0a98ae0?s=64&d=identicon&r=PG)](https://serverfault.com/users/76757/kcd) [KCD](https://serverfault.com/users/76757/kcd) 97833 gold badges1313 silver badges2424 bronze badges answered May 5, 2009 at 13:21 user1797 5 - 2 Future versions of windows include RoboCopy. From Vista's XCOPY: "NOTE: Xcopy is now deprecated, please use Robocopy." George Tsiokos – [George Tsiokos](https://serverfault.com/users/45322/george-tsiokos "185 reputation") 2009-05-18 16:28:37 +00:00 [Commented May 18, 2009 at 16:28](https://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files#comment6754_4669) - 1 Interestingly enough, two years later after your comment, George, xcopy still 'rules the world' on Windows 7. user1797 – user1797 2011-08-25 17:22:38 +00:00 [Commented Aug 25, 2011 at 17:22](https://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files#comment292166_4669) - Note that embedded Windows XP environments (POSReady 2009, etc) doesn't ship with xcopy. Epoc – [Epoc](https://serverfault.com/users/168028/epoc "101 reputation") 2014-09-22 15:54:06 +00:00 [Commented Sep 22, 2014 at 15:54](https://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files#comment757693_4669) - I've suggested an edit to list allllll these options...! If you are not automating it `/E /H` and maybe `/K /O` gets you a long way with a few handy prompts KCD – [KCD](https://serverfault.com/users/76757/kcd "978 reputation") 2015-06-25 23:07:27 +00:00 [Commented Jun 25, 2015 at 23:07](https://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files#comment868073_4669) - Don't forget `/J`, which prevents [a bug with XCopy](https://en.wikipedia.org/wiki/XCOPY#Limitation) when copying large files. I'm not sure why they wouldn't make that the default... BlueRaja – [BlueRaja](https://serverfault.com/users/41533/blueraja "1,376 reputation") 2015-07-08 10:21:37 +00:00 [Commented Jul 8, 2015 at 10:21](https://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files#comment871978_4669) [Add a comment](https://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files "Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.") \| This answer is useful 10 Save this answer. Show activity on this post. Use *md* to create the folder (it's ok if it already exists) Use *copy* or *move* for files, and *xcopy* for folders [Share](https://serverfault.com/a/4640 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/ "The current license for this post: CC BY-SA 2.5") [Improve this answer](https://serverfault.com/posts/4640/edit) Follow Follow this answer to receive notifications answered May 5, 2009 at 12:52 [![Dani's user avatar](https://www.gravatar.com/avatar/b76194f24bfb4bafc129ba945718b2f4?s=64&d=identicon&r=PG)](https://serverfault.com/users/588/dani) [Dani](https://serverfault.com/users/588/dani) 1,22611 gold badge1313 silver badges2020 bronze badges 3 - Can you give me an example of the syntax? David Basarab – [David Basarab](https://serverfault.com/users/823/david-basarab "1,197 reputation") 2009-05-05 12:55:15 +00:00 [Commented May 5, 2009 at 12:55](https://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files#comment2789_4640) - 3 copy fred.txt copy\_of\_fred.txt Adam Gibbins – [Adam Gibbins](https://serverfault.com/users/914/adam-gibbins "7,655 reputation") 2009-05-05 13:04:20 +00:00 [Commented May 5, 2009 at 13:04](https://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files#comment2796_4640) - 1 copy /? will give you the help text, sort of like a DOS man page. Scottie T – [Scottie T](https://serverfault.com/users/785/scottie-t "245 reputation") 2009-05-05 13:34:11 +00:00 [Commented May 5, 2009 at 13:34](https://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files#comment2808_4640) [Add a comment](https://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files "Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.") \| This answer is useful 5 Save this answer. Show activity on this post. 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. *** 1. 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: ``` robocopy C:\tools D:\backup\tools /e ``` 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. 2. 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\] ``` robocopy "C:\Users\My Documents" "D:\backup\My Documents" /mir ``` This function will preserve all permissions of the original files. 3. Enable restarting. You may want to include the ability to restart the process in case the connection is severed mid-copy. ``` robocopy "C:\Users\My Documents" "D:\backup\My Documents" /z ``` 4. 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. ``` robocopy "C:\Users\My Documents" "D:\backup\My Documents" /log+:<filename>.txt ``` 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. [Share](https://serverfault.com/a/738204 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://serverfault.com/posts/738204/edit) Follow Follow this answer to receive notifications answered Nov 22, 2015 at 21:39 [![Program-Me-Rev's user avatar](https://www.gravatar.com/avatar/949d87a446a4ebe7e7370b0f58ba4692?s=64&d=identicon&r=PG&f=y&so-version=2)](https://serverfault.com/users/323631/program-me-rev) [Program-Me-Rev](https://serverfault.com/users/323631/program-me-rev) 15111 silver badge33 bronze badges [Add a comment](https://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files "Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.") \| This answer is useful 3 Save this answer. Show activity on this post. In a batch file: ``` if not exists locationB\nul mkdir locationB copy locationA\file locationB ``` `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 directory `locationA` to `locationB` and names the file the same thing. If you want to rename the file at the same time, you can do that too: ``` copy locationA\file locationB\newfilename ``` [Share](https://serverfault.com/a/4668 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/ "The current license for this post: CC BY-SA 2.5") [Improve this answer](https://serverfault.com/posts/4668/edit) Follow Follow this answer to receive notifications answered May 5, 2009 at 13:21 [![Graeme Perrow's user avatar](https://www.gravatar.com/avatar/2fcdc79d20203f12b3bdd7723de5a6f1?s=64&d=identicon&r=PG)](https://serverfault.com/users/355/graeme-perrow) [Graeme Perrow](https://serverfault.com/users/355/graeme-perrow) 55511 gold badge66 silver badges1717 bronze badges [Add a comment](https://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files "Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.") \| This answer is useful 2 Save this answer. Show activity on this post. 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. [Share](https://serverfault.com/a/4690 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/ "The current license for this post: CC BY-SA 2.5") [Improve this answer](https://serverfault.com/posts/4690/edit) Follow Follow this answer to receive notifications answered May 5, 2009 at 13:51 [![Richard's user avatar](https://www.gravatar.com/avatar/95e28ac250c4604a6f9d7e34705c3259?s=64&d=identicon&r=PG)](https://serverfault.com/users/1440/richard) [Richard](https://serverfault.com/users/1440/richard) 5,38411 gold badge2525 silver badges2222 bronze badges 1 - For anything important, I'm going to go with robocopy, as well. I seem to remember a huge performance difference over xcopy when synching a large number of files. Kara Marfia – [Kara Marfia](https://serverfault.com/users/1803/kara-marfia "7,892 reputation") 2009-05-05 14:03:51 +00:00 [Commented May 5, 2009 at 14:03](https://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files#comment2823_4690) [Add a comment](https://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files "Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.") \| This answer is useful 0 Save this answer. Show activity on this post. 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. ``` xcopy /I c:\<SourceDir>\<SourceFile> c:\<TargetDirThatDoesNOTExist> ``` I'd also look at RoboCopy, but you need to get it from the resource kit as it's not in Windows until Vista. [Share](https://serverfault.com/a/4670 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/ "The current license for this post: CC BY-SA 2.5") [Improve this answer](https://serverfault.com/posts/4670/edit) Follow Follow this answer to receive notifications answered May 5, 2009 at 13:21 [![WaldenL's user avatar](https://www.gravatar.com/avatar/0cce447a9752d260c877e5020f3b64a0?s=64&d=identicon&r=PG)](https://serverfault.com/users/1562/waldenl) [WaldenL](https://serverfault.com/users/1562/waldenl) 1,27011 gold badge1414 silver badges2727 bronze badges [Add a comment](https://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files "Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.") \| This answer is useful \-1 Save this answer. Show activity on this post. 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 [Share](https://serverfault.com/a/697995 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://serverfault.com/posts/697995/edit) Follow Follow this answer to receive notifications answered Jun 10, 2015 at 15:25 [![Jeff's user avatar](https://www.gravatar.com/avatar/f030d75644c424326dfd364ececa57db?s=64&d=identicon&r=PG)](https://serverfault.com/users/293482/jeff) [Jeff](https://serverfault.com/users/293482/jeff) 1 1 - 1 Does not make sense to reply such an old question, which already has an accepted answer and not contributing some value added on your answer. alphamikevictor – [alphamikevictor](https://serverfault.com/users/274818/alphamikevictor "1,062 reputation") 2015-06-10 15:33:34 +00:00 [Commented Jun 10, 2015 at 15:33](https://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files#comment862341_697995) [Add a comment](https://serverfault.com/questions/4639/what-is-the-windows-command-line-command-to-copy-files "Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.") \| ## You must [log in](https://serverfault.com/users/login?ssrc=question_page&returnurl=https%3A%2F%2Fserverfault.com%2Fquestions%2F4639) to answer this question. Start asking to get answers Find the answer to your question by asking. [Ask question](https://serverfault.com/questions/ask) Explore related questions - [windows](https://serverfault.com/questions/tagged/windows "show questions tagged 'windows'") - [command-line-interface](https://serverfault.com/questions/tagged/command-line-interface "show questions tagged 'command-line-interface'") - [copy](https://serverfault.com/questions/tagged/copy "show questions tagged 'copy'") See similar questions with these tags. - The Overflow Blog - [Seizing the means of messenger production](https://stackoverflow.blog/2026/04/03/seizing-the-means-of-messenger-production/?cb=1) - [How can you test your code when you don’t know what’s in it?](https://stackoverflow.blog/2026/03/31/how-can-you-test-your-code-when-you-don-t-know-what-s-in-it/?cb=1) #### Related [276](https://serverfault.com/questions/3780/useful-command-line-commands-on-windows?rq=1 "Question score (upvotes - downvotes)") [Useful Command-line Commands on Windows](https://serverfault.com/questions/3780/useful-command-line-commands-on-windows?rq=1) [2](https://serverfault.com/questions/4644/how-to-install-program-so-it-is-accessible-from-command-line-regardless-of-locat?rq=1 "Question score (upvotes - downvotes)") [How to install program so it is accessible from command line regardless of location?](https://serverfault.com/questions/4644/how-to-install-program-so-it-is-accessible-from-command-line-regardless-of-locat?rq=1) [150](https://serverfault.com/questions/7056/whats-the-reverse-dns-command-line-utility?rq=1 "Question score (upvotes - downvotes)") [What's the reverse DNS command line utility?](https://serverfault.com/questions/7056/whats-the-reverse-dns-command-line-utility?rq=1) [317](https://serverfault.com/questions/41064/whats-the-command-line-utility-in-windows-to-do-a-reverse-dns-look-up?rq=1 "Question score (upvotes - downvotes)") [What's the command-line utility in Windows to do a reverse DNS look-up?](https://serverfault.com/questions/41064/whats-the-command-line-utility-in-windows-to-do-a-reverse-dns-look-up?rq=1) [20](https://serverfault.com/questions/204303/how-do-i-copy-a-directory-tree-but-not-the-files-in-linux?rq=1 "Question score (upvotes - downvotes)") [How do I copy a directory tree but not the files in Linux?](https://serverfault.com/questions/204303/how-do-i-copy-a-directory-tree-but-not-the-files-in-linux?rq=1) [18](https://serverfault.com/questions/370403/copy-a-range-of-files-in-command-line-zsh-bash?rq=1 "Question score (upvotes - downvotes)") [Copy a range of files in command line (ZSH/BASH)](https://serverfault.com/questions/370403/copy-a-range-of-files-in-command-line-zsh-bash?rq=1) [1](https://serverfault.com/questions/371266/command-line-folder-structure-on-windows?rq=1 "Question score (upvotes - downvotes)") [Command-Line folder structure on Windows](https://serverfault.com/questions/371266/command-line-folder-structure-on-windows?rq=1) [0](https://serverfault.com/questions/528415/how-to-copy-many-files-within-windows-lan-through-ssh-fast?rq=1 "Question score (upvotes - downvotes)") [How to copy many files within Windows LAN through ssh fast](https://serverfault.com/questions/528415/how-to-copy-many-files-within-windows-lan-through-ssh-fast?rq=1) [1](https://serverfault.com/questions/551441/why-would-some-folders-be-invisible-on-the-command-line?rq=1 "Question score (upvotes - downvotes)") [Why would some folders be invisible on the command line?](https://serverfault.com/questions/551441/why-would-some-folders-be-invisible-on-the-command-line?rq=1) [3](https://serverfault.com/questions/1002544/check-effective-permissions-effective-access-from-command-line-windows-ntf?rq=1 "Question score (upvotes - downvotes)") [Check 'effective permissions', 'effective access' from command-line, Windows/NTFS](https://serverfault.com/questions/1002544/check-effective-permissions-effective-access-from-command-line-windows-ntf?rq=1) #### [Hot Network Questions](https://stackexchange.com/questions?tab=hot) - [Fix large spacing when using align with cases](https://tex.stackexchange.com/questions/761573/fix-large-spacing-when-using-align-with-cases) - [Converting a data set into a data frame](https://stackoverflow.com/questions/79919771/converting-a-data-set-into-a-data-frame) - [How to choose critical p-value?](https://stats.stackexchange.com/questions/675464/how-to-choose-critical-p-value) - [Simple passive audio panning circuit using double-gang pot?](https://electronics.stackexchange.com/questions/767716/simple-passive-audio-panning-circuit-using-double-gang-pot) - [Celesta notation question](https://music.stackexchange.com/questions/143462/celesta-notation-question) - [Does every finite direct category have filtered colimits?](https://mathoverflow.net/questions/509853/does-every-finite-direct-category-have-filtered-colimits) - [How to create a quad sphere with uniform faces in Geometry Nodes?](https://blender.stackexchange.com/questions/346068/how-to-create-a-quad-sphere-with-uniform-faces-in-geometry-nodes) - [How does David Lewis's argument in 'Why Ain'cha Rich?' support his view?](https://philosophy.stackexchange.com/questions/137508/how-does-david-lewiss-argument-in-why-aincha-rich-support-his-view) - [Using GenAI for PhD Research: Productivity vs Enjoyment](https://academia.stackexchange.com/questions/226350/using-genai-for-phd-research-productivity-vs-enjoyment) - [Short story about an alien plot to invade using telepathy to influence a human](https://scifi.stackexchange.com/questions/303933/short-story-about-an-alien-plot-to-invade-using-telepathy-to-influence-a-human) - [Why doesn't "一" have a Numeric value in Debian's unicode utility?](https://unix.stackexchange.com/questions/805290/why-doesnt-%E4%B8%80-have-a-numeric-value-in-debians-unicode-utility) - [Cryptic clue: “Piece dark, we hear (6)”](https://puzzling.stackexchange.com/questions/137580/cryptic-clue-piece-dark-we-hear-6) - [What form does kinetic energy take in the classical (non-relativistic) Lagrangian?](https://physics.stackexchange.com/questions/870847/what-form-does-kinetic-energy-take-in-the-classical-non-relativistic-lagrangia) - [How to draw an SVG using paths in Tikz picture?](https://tex.stackexchange.com/questions/761598/how-to-draw-an-svg-using-paths-in-tikz-picture) - [Rear mech catching frame](https://bicycles.stackexchange.com/questions/100145/rear-mech-catching-frame) - [Can I leave the airport during a long layover at Addis Ababa airport?](https://travel.stackexchange.com/questions/203534/can-i-leave-the-airport-during-a-long-layover-at-addis-ababa-airport) - [What do "Lieutenant Nature" and "footstoole crack" mean in Donne's "Good Friday"?](https://literature.stackexchange.com/questions/31869/what-do-lieutenant-nature-and-footstoole-crack-mean-in-donnes-good-friday) - [How to create a four-line style arrow and apply the style of a native LaTeX font? (include⟰⟱)](https://tex.stackexchange.com/questions/761569/how-to-create-a-four-line-style-arrow-and-apply-the-style-of-a-native-latex-font) - [Why does a function seem to be executed more times than the number of elements passed to np.vectorize(function)?](https://stackoverflow.com/questions/79919603/why-does-a-function-seem-to-be-executed-more-times-than-the-number-of-elements-p) - [Can you Magical Hack a Magical Hack?](https://boardgames.stackexchange.com/questions/64445/can-you-magical-hack-a-magical-hack) - [Pam Bondi was fired as attorney general. Will she still have to sit for a deposition?](https://politics.stackexchange.com/questions/94484/pam-bondi-was-fired-as-attorney-general-will-she-still-have-to-sit-for-a-deposi) - [Each onto function between compact topological Hausdorff spaces, is irreducable under the restriction to some subset of its domain](https://math.stackexchange.com/questions/5131547/each-onto-function-between-compact-topological-hausdorff-spaces-is-irreducable) - [Rule for differentiating via multiple pathways](https://math.stackexchange.com/questions/5131518/rule-for-differentiating-via-multiple-pathways) - [What does 'basic movement' refer to?](https://electronics.stackexchange.com/questions/767700/what-does-basic-movement-refer-to) [Question feed](https://serverfault.com/feeds/question/4639 "Feed of this question and its answers") # Subscribe to RSS Question feed To subscribe to this RSS feed, copy and paste this URL into your RSS reader. ![](https://serverfault.com/posts/4639/ivc/11f8?prg=24aec9dc-874d-40c8-af89-22a7d1840f17) # Why are you flagging this comment? It contains harassment, bigotry or abuse. This comment attacks a person or group. Learn more in our [Abusive behavior policy](https://serverfault.com/conduct/abusive-behavior). It's unfriendly or unkind. This comment is rude or condescending. Learn more in our [Code of Conduct](https://serverfault.com/conduct/abusive-behavior). Not needed. This comment is not relevant to the post. ``` ``` Enter at least 6 characters Something else. A problem not listed above. Try to be as specific as possible. ``` ``` Enter at least 6 characters Flag comment Cancel You have 0 flags left today # ![Illustration of upvote icon after it is clicked](https://serverfault.com/Content/Img/modal/img-upvote.png?v=fce73bd9724d) # Hang on, you can't upvote just yet. You'll need to complete a few actions and gain 15 reputation points before being able to upvote. **Upvoting** indicates when questions and answers are useful. [What's reputation and how do I get it?](https://stackoverflow.com/help/whats-reputation) Instead, you can save this post to reference later. Save this post for later Not now ##### [Server Fault](https://serverfault.com/) - [Tour](https://serverfault.com/tour) - [Help](https://serverfault.com/help) - [Chat](https://chat.stackexchange.com/?tab=site&host=serverfault.com) - [Contact](https://serverfault.com/contact) - [Feedback](https://meta.serverfault.com/) ##### [Company](https://stackoverflow.co/) - [Stack Overflow](https://stackoverflow.com/) - [Stack Internal](https://stackoverflow.co/internal/) - [Stack Data Licensing](https://stackoverflow.co/data-licensing/) - [Stack Ads](https://stackoverflow.co/advertising/) - [About](https://stackoverflow.co/) - [Press](https://stackoverflow.co/company/press/) - [Legal](https://stackoverflow.com/legal) - [Privacy Policy](https://stackoverflow.com/legal/privacy-policy) - [Terms of Service](https://stackoverflow.com/legal/terms-of-service/public) - Cookie Settings - [Cookie Policy](https://policies.stackoverflow.co/stack-overflow/cookie-policy) ##### [Stack Exchange Network](https://stackexchange.com/) - [Technology](https://stackexchange.com/sites#technology) - [Culture & recreation](https://stackexchange.com/sites#culturerecreation) - [Life & arts](https://stackexchange.com/sites#lifearts) - [Science](https://stackexchange.com/sites#science) - [Professional](https://stackexchange.com/sites#professional) - [Business](https://stackexchange.com/sites#business) - [API](https://api.stackexchange.com/) - [Data](https://data.stackexchange.com/) - [Blog](http://blog.serverfault.com/?blb=1) - [Facebook](https://www.facebook.com/officialstackoverflow/) - [Twitter](https://twitter.com/stackoverflow) - [LinkedIn](https://linkedin.com/company/stack-overflow) - [Instagram](https://www.instagram.com/thestackoverflow) Site design / logo © 2026 Stack Exchange Inc; user contributions licensed under [CC BY-SA](https://stackoverflow.com/help/licensing) . rev 2026.4.2.41748
Readable Markdown
This question shows research effort; it is useful and clear 45 Save this question. Show activity on this post. 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. asked May 5, 2009 at 12:50 [![David Basarab's user avatar](https://www.gravatar.com/avatar/200cc24cc0555d1c6bd14b5a7fe8f852?s=64&d=identicon&r=PG)](https://serverfault.com/users/823/david-basarab) 1 This answer is useful 55 Save this answer. Show activity on this post. The command `xcopy` is what you are looking for. Example: ``` xcopy source destination /E /C /H /R /K /O /Y ``` 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. ``` /E Copies directories and subdirectories, including empty ones. Same as /S /E. May be used to modify /T. /C Continues copying even if errors occur. /H Copies hidden and system files also. /R Overwrites read-only files. /K Copies attributes. Normal Xcopy will reset read-only attributes. /O Copies file ownership and ACL information. /Y Suppresses prompting to confirm you want to overwrite an existing destination file. ``` For more info type `xcopy /?` and your command line. [![KCD's user avatar](https://www.gravatar.com/avatar/22de692b5c4bba0665322370e0a98ae0?s=64&d=identicon&r=PG)](https://serverfault.com/users/76757/kcd) [KCD](https://serverfault.com/users/76757/kcd) 9783 gold badges13 silver badges24 bronze badges answered May 5, 2009 at 13:21 5 This answer is useful 10 Save this answer. Show activity on this post. Use *md* to create the folder (it's ok if it already exists) Use *copy* or *move* for files, and *xcopy* for folders answered May 5, 2009 at 12:52 [![Dani's user avatar](https://www.gravatar.com/avatar/b76194f24bfb4bafc129ba945718b2f4?s=64&d=identicon&r=PG)](https://serverfault.com/users/588/dani) 3 This answer is useful 5 Save this answer. Show activity on this post. 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. *** 1. 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: ``` robocopy C:\tools D:\backup\tools /e ``` 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. 2. 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\] ``` robocopy "C:\Users\My Documents" "D:\backup\My Documents" /mir ``` This function will preserve all permissions of the original files. 3. Enable restarting. You may want to include the ability to restart the process in case the connection is severed mid-copy. ``` robocopy "C:\Users\My Documents" "D:\backup\My Documents" /z ``` 4. 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. ``` robocopy "C:\Users\My Documents" "D:\backup\My Documents" /log+:<filename>.txt ``` 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. answered Nov 22, 2015 at 21:39 [![Program-Me-Rev's user avatar](https://www.gravatar.com/avatar/949d87a446a4ebe7e7370b0f58ba4692?s=64&d=identicon&r=PG&f=y&so-version=2)](https://serverfault.com/users/323631/program-me-rev) This answer is useful 3 Save this answer. Show activity on this post. In a batch file: ``` if not exists locationB\nul mkdir locationB copy locationA\file locationB ``` `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 directory `locationA` to `locationB` and names the file the same thing. If you want to rename the file at the same time, you can do that too: ``` copy locationA\file locationB\newfilename ``` answered May 5, 2009 at 13:21 [![Graeme Perrow's user avatar](https://www.gravatar.com/avatar/2fcdc79d20203f12b3bdd7723de5a6f1?s=64&d=identicon&r=PG)](https://serverfault.com/users/355/graeme-perrow) This answer is useful 2 Save this answer. Show activity on this post. 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. answered May 5, 2009 at 13:51 [![Richard's user avatar](https://www.gravatar.com/avatar/95e28ac250c4604a6f9d7e34705c3259?s=64&d=identicon&r=PG)](https://serverfault.com/users/1440/richard) 1 This answer is useful 0 Save this answer. Show activity on this post. 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. ``` xcopy /I c:\<SourceDir>\<SourceFile> c:\<TargetDirThatDoesNOTExist> ``` I'd also look at RoboCopy, but you need to get it from the resource kit as it's not in Windows until Vista. answered May 5, 2009 at 13:21 [![WaldenL's user avatar](https://www.gravatar.com/avatar/0cce447a9752d260c877e5020f3b64a0?s=64&d=identicon&r=PG)](https://serverfault.com/users/1562/waldenl) This answer is useful \-1 Save this answer. Show activity on this post. 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 answered Jun 10, 2015 at 15:25 [![Jeff's user avatar](https://www.gravatar.com/avatar/f030d75644c424326dfd364ececa57db?s=64&d=identicon&r=PG)](https://serverfault.com/users/293482/jeff) 1 ## You must [log in](https://serverfault.com/users/login?ssrc=question_page&returnurl=https%3A%2F%2Fserverfault.com%2Fquestions%2F4639) to answer this question. Start asking to get answers Find the answer to your question by asking. [Ask question](https://serverfault.com/questions/ask) Explore related questions See similar questions with these tags.
Shard19 (laksa)
Root Hash4232792808108743419
Unparsed URLcom,serverfault!/questions/4639/what-is-the-windows-command-line-command-to-copy-files s443