batch to copy files with xcopy
Asked Answered
L

4

9

I have checked some examples on internet but I can't get my (first) batch file to work. I would like to copy automatically my file from a folder to another one but nothing happen.

@echo off
xcopy "C:\source\" "C:\target\" /c /d /i /y
exit

Could you see anything wrong?

Thanks!!

Update: I have done the command given by Bali C but it still doesn't work. See snapshot

xcopy C:\folder1 C:\folder2\folder1 /t /e /i /y
xcopy C:\folder1 C:\folder2\ /t /e /i /y

Image:
image

I have to stop it with CTRL + C.

PS: I'm on Win 7

Update (Solution): It works! The problem was the name xcopy,bat on my Desktop, and I was running the command from there, so it was executing the xcopy.bat file of my desktop instead of the Windows one.. I had to rename the file with "myxcopy.bat" :

@echo off
xcopy "C:\source" "C:\target" /c /d /i /y
exit
Lactobacillus answered 2/2, 2012 at 15:23 Comment(3)
What is the name of your batch file? From your screenshot, I'm guessing it's XCOPY.BAT. Try renaming to something else, like MyXcopy.bat.Sedan
I'm honestly not sure then, I tried the exact command you tried in the screenshot (top one from my answer) and it worked fine, straight away. Unless you don't have permissions on those folders?Stratosphere
Yes, if it was named XCOPY.BAT, that would definitely cause a problem. Every time you called XCOPY in your batch file, you would be calling another instance of XCOPY.BAT instead of the XCOPY command.Sedan
S
8

After testing most of the switches this worked for me:

xcopy C:\folder1 C:\folder2\folder1 /t /e /i /y

This will copy the folder folder1 into the folder folder2. So the directory tree would look like:

C:
   Folder1
   Folder2
      Folder1
Stratosphere answered 2/2, 2012 at 15:32 Comment(10)
I tried removing some options or just /c /y But it doesn't change anything, I get the cursor blinking on the next line as wellLactobacillus
Could you post the exact code you are using? With the filename included?Stratosphere
Actually, \S copies directories and subdirectories except empty ones.Sedan
Your answer is still not right. \S will copy directories and subdirectories except empty ones. If a directory contains files/folders, it will get copied...if a directory does not contain files/folders it will not get copied.Sedan
Lol I'm getting confused, since I'm presuming the file will be there the s switch won't cause a problem, just removed it from my answer.Stratosphere
I tried different combinaisons of Options but still, do you manage to do it on your own computer? I have updated my question with the content of my xcopy.bat fileLactobacillus
The command you are using is trying to copy a folder, if you are copying a file you need to specify the file like in my answer. Are you copying a folder or a file?Stratosphere
I'am trying to copy a folder, containing others files and foldersLactobacillus
Edited answer, hopefully this should fix it :)Stratosphere
here you can find what does /t e/ /i /y mean: technet.microsoft.com/en-us/library/cc771254.aspxClevis
F
5

Based on xcopy help, I tried and found that following works perfectly for me (tried on Win 7)

xcopy C:\folder1 C:\folder2\folder1 /E /C /I /Q /G /H /R /K /Y /Z /J
Federalist answered 17/12, 2012 at 18:23 Comment(1)
best one for bringing over subdirectories and files at every levelPelaga
T
4

If the requirement is to copy all files in "\Publish\Appfolder" into the parent "\Publish\" folder (inclusive of any subfolders, following works for me) The switch '/s' allows copying of all subfolders, recursively.

xcopy src\main\Publish\Appfolder\*.* /s src\main\Publish\

Tunstall answered 22/8, 2016 at 12:29 Comment(0)
G
3

You must specify your file in the copy:

xcopy C:\source\myfile.txt C:\target

Or if you want to copy all txt files for example

xcopy C:\source\*.txt C:\target
Gwenngwenneth answered 2/2, 2012 at 15:27 Comment(1)
I tried xcopy C:\source*.txt C:\target But it doesn't change anything, I get the cursor blinking on the next lineLactobacillus

© 2022 - 2024 — McMap. All rights reserved.