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
)
I want to use Xcopy to copy that file with its full directory into D:\Copied
, then I should have something like this ---> D:\Copie开发者_Go百科d\Majid\File\text.txt
, as you see the drive letter is removed and all of other directory is created in destination directory.
How can I do this action by XCopy?
see this:
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] ...
what you will find interesting in that page is this:
/s : Copies directories and subdirectories, unless they are empty. If you omit /s, xcopy works within a single directory.
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").
this one was good for me
xcopy $(SolutionDir)Libs\YourFolder\* $(TargetDir)YourFolder /s /i /r
source
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. 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#
精彩评论