5

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:\Copied\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?

Inside Man
  • 4,194
  • 12
  • 59
  • 119
  • are you planning to execute this command manually from the console or from a program you made yourself? Which language? If manually execution this does not belong here in SO! – Davide Piras Sep 05 '11 at 06:15
  • 1
    I disagree Davide, I think this is a reasonable question. – Toby Allen Sep 05 '11 at 06:50

5 Answers5

1

this one was good for me

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

source

Wahid Bitar
  • 13,776
  • 13
  • 78
  • 106
1

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.

Davide Piras
  • 43,984
  • 10
  • 98
  • 147
  • Hi Davide, I have an application which monitors a directory for new files, after that you can execute an application for those files, I want to use Xcopy for it. /s command will not work. Imagine my file is C:\Majid\Text.txt, If I use /s it only copy text.txt and won' create Majid folder on destination folder. What should I do? – Inside Man Sep 05 '11 at 06:36
1
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").

daniel
  • 471
  • 1
  • 4
  • 13
  • Hi daniel, Nice Answer, But it will ask a question while executing.It will ask the target directory is a file name or directory, and I should enter F or D. I do not want to se this message and set its default option to D. How to that Daniel? Thanks For your Nice answer again :) – Inside Man Jan 11 '12 at 14:42
0

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 ;)

Inside Man
  • 4,194
  • 12
  • 59
  • 119
-1

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#

incubuzz1978
  • 53
  • 1
  • 8
  • The question is about XCopy from the command line. It asks nothing about C# or `Process.Start`, and your answer is full of variables and function calls that mean nothing from the command line. I'm not sure how this is supposed to answer the question asked here. – Ken White Sep 26 '13 at 16:19