Copy files with the exact structure to another directory using XCopy

I 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 this file with the full directory to D:\Copied , then I should get something like this ---> D:\Copied\Majid\File\text.txt , since you see that drive letter is deleted, and all other directories created in the destination directory.

How to do it with XCopy?

+5
source share
5 answers

Here he is:

 set sourceFolder="C:\Users\User\Desktop\34\*" set destinationFolder=%sourceFolder:~3,-1% xcopy %sourceFolder% "D:\xcopied%destinationFolder%" /s /i /r 

based on answers from @daniel and @WahidBitar. Thank you men;)

0
source

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 find interesting on this page:

/ s : copies directories and subdirectories if they are not empty. If you omit / s, xcopy runs within the same directory.

+1
source
 set sourceFolder="C:\test\new folder\text.txt" set destinationFolder=%sourceFolder:~3,-1% echo %destinationFolder% xcopy %sourceFolder% "D:\xcopied%destinationFolder%" 

Something like this might work. Delete the first few characters of the source ("C:"), then add the characters for the destination folder ("D: \ xcopied").

+1
source

this one was good for me

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

a source

+1
source

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 a star at the end of the line, I got rid of the question, be it a file or a directory, since you did not specify anything in the way you want to use it ... here is the solution for C #

-one
source

All Articles