简体   繁体   中英

Copy single file instead of entire directory in windows batch

Let's suppose that I am in some directory with two subdirectories, a and b . a has two files in it: t1.txt and t2.txt . That is, I have the following directory structure:

/.
  /a
    t1.txt
    t2.txt
  /b

I want to copy the file t1.txt from the a directory into the b directory.

I tried the following command

copy /b a/t1.txt b/t1.txt

but it copies the entire a directory into the b directory.

Why does this happen, and how can I make it so that only the t1.txt file is copied?

When copying to a new directory, you only need to specify the new directory . So

 copy /b a\t1.txt b

should work.

That said, I don't think additionally specifying the file name would cause the error you've described -- the official help text says "Destination can consist of a drive letter and colon, a folder name, a file name, or a combination of these," which to me implies that how you have it is fine.

I've also reversed the slashes -- were you using forward slashes in your batch file or is that a typo in the post? Maybe that was the problem?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM