简体   繁体   English

使用XCopy将具有精确结构的文件复制到另一个目录中

[英]Copy Files with exact Structure into another Directory using XCopy

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:\\CopiedD:\\CopiedC:\\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:\\CopiedD:\\Copied ,然后我应该有这样的东西---> D:\\Copied\\Majid\\File\\text.txt ,因为你看到驱动器号是已删除,并且在目标目录中创建了所有其他目录。

How can I do this action by XCopy? 我怎样才能通过XCopy执行此操作?

this one was good for me 这个对我有好处

xcopy $(SolutionDir)Libs\YourFolder\* $(TargetDir)YourFolder /s /i /r

source 资源

see this: 看到这个:

XCOPY COMMAND XCOPY COMMAND

... 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源[目的地] [/ 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. / s :复制目录和子目录,除非它们是空的。 If you omit /s, xcopy works within a single directory. 如果省略/ s,则xcopy在单个目录中工作。

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”)。

Here it is: 这里是:

set sourceFolder="C:\Users\User\Desktop\34\*"
set destinationFolder=%sourceFolder:~3,-1%

xcopy %sourceFolder%  "D:\xcopied%destinationFolder%" /s /i /r

based on @daniel and @WahidBitar answers. 基于@daniel和@WahidBitar答案。 Thank you men ;) 谢谢你的男人;)

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#的解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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