windows 使用 XCopy 将具有精确结构的文件复制到另一个目录中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7304359/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Copy Files with exact Structure into another Directory using XCopy
提问by Inside Man
Think I want to copy this file C:\Majid\File\text.txt
to D:\Copied
(C:\Majid\File\text.txt ---> D:\Copied
)
想我想把这个文件复制C:\Majid\File\text.txt
到D:\Copied
( C:\Majid\File\text.txt ---> D:\Copied
)
I want to use Xcopy to copy that file with its full directory into D:\Copied
, then I should have something like this ---> D:\Copied\Majid\File\text.txt
, as you see the drive letter is removed and all of other directory is created in destination directory.
我想用Xcopy将这个文件拷贝其完整的目录进入D:\Copied
,那么我应该有这样的事情---> D:\Copied\Majid\File\text.txt
,因为你看到的盘符被删除,所有其他目录的在目标目录中创建。
How can I do this action by XCopy?
我如何通过 XCopy 执行此操作?
采纳答案by Inside Man
Here it is:
这里是:
set sourceFolder="C:\Users\User\Desktop\*"
set destinationFolder=%sourceFolder:~3,-1%
xcopy %sourceFolder% "D:\xcopied%destinationFolder%" /s /i /r
based on @daniel and @WahidBitar answers. Thank you men ;)
基于@daniel 和@WahidBitar 的回答。谢谢你们 ;)
回答by Davide Piras
see this:
看到这个:
... Syntax xcopy Source [Destination] [/w] [/p] [/c] [/v] [/q] [/f] [/l] [/g] [/d[:mm-dd-yyyy]] [/u] [/i] [/s [/e]] [/t] [/k] [/r] [/h] [{/a|/m}] [/n] [/o] [/x] [/exclude:file1[+[file2]][+[file3]] [{/y|/-y}] [/z] ...
... 语法 xcopy Source [Destination] [/w] [/p] [/c] [/v] [/q] [/f] [/l] [/g] [/d[:mm-dd- yyyy]] [/u] [/i] [/s [/e]] [/t] [/k] [/r] [/h] [{/a|/m}] [/n] [/ o] [/x] [/exclude:file1[+[file2]][+[file3]] [{/y|/-y}] [/z] ...
what you will find interesting in that page is this:
您会在该页面中发现有趣的是:
/s: Copies directories and subdirectories, unless they are empty. If you omit /s, xcopyworks within a single directory.
/s:复制目录和子目录,除非它们为空。如果省略/s,xcopy 将在单个目录中工作。
回答by daniel
set sourceFolder="C:\test\new folder\text.txt"
set destinationFolder=%sourceFolder:~3,-1%
echo %destinationFolder%
xcopy %sourceFolder% "D:\xcopied%destinationFolder%"
Something like that could work. Remove the first few characters of the source ("C:"), then add the characters for the destination folder ("D:\xcopied").
像这样的东西可以工作。删除源文件的前几个字符(“C:”),然后添加目标文件夹的字符(“D:\xcopied”)。
回答by Wahid Bitar
回答by incubuzz1978
try something like this:
尝试这样的事情:
System.Diagnostics.Process.Start
("XCOPY.EXE", "/E /I /Y " + filename + " "
+ pfadauswahl + "Backup\" + dt.ToString("yyyy-MM-dd")
+ "\UserData\" + File_Name + "* ");
with the star at the end of the line, i got rid of the question if its either a file or a dir.. since you didn't specify anything on how you want to use it... here is the solution for c#
随着行尾的星号,我摆脱了它是文件还是目录的问题..因为你没有指定任何关于你想如何使用它的东西......这是c#的解决方案