I have a txt file with the full path for .jpg files, I need to xcopy the whole folders including everything inside using xcopy using batch file
This is an old question, but I had the same question and neither of the above answers quite did it for me. I had to add /s:
xcopy C:\path\to\source\directory D:\path\to\destination\ /e /i /y /s
That copys all files, subfolders, and files in subfolders. More (and helpful) documentation available here:
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/xcopy
xcopy /? will show you the options you can use. You probably want something like xcopy C:\path\to\source\directory D:\path\to\destination\ /e /i /y
Something like this should do it
FOR /F "delims=" %%i IN (c:\temp\paths.txt) DO xcopy "%%i*.jpg" "C:\test\" /s /y
Related
set /P source=C:\Users\akshjosh\Documents\PROJECTS\119657_119578\119657\Config
set /P destination=C:\Users\akshjosh\Documents\PROJECTS\119657_119578\119657\Hi
set xcopy=xcopy /S/E/V/Q/F/H/I/N
%xcopy% %source% %destination%
this does not work.
Can anyone tell me what's wrong ?
Update:
The following code works but it creates the entire directory structure inside the destination. I only want the files to be copied.
xcopy /s /e /y "C:\Users\akshjosh\Documents\PROJECTS\119657_119578\119657\Config" "C:\Users\akshjosh\Documents\PROJECTS\119657_119578\119657\Hi"
pause
You need to remove the /p following the set commands. Also for the xcopy command you included switches that contradict themselves, ex. /s and /e. Look up the documentation on them.
You also need to change the variable name of xcopy to something that isn't already an inbuilt command.
set source=//FileLocation//
set destination=//FileDestination//
xcopy %source% %destination% /E /V /F /H /N
This should copy the files over with the directory structure. If you are still looking for only the files then I would recommend using a for loop to loop over all the files and transfer them that way. See here How to copy only files(not directories) using batch file?
I am trying to run a simple xcopy batch script but I am facing some difficoulties.
Here is the script
SET SRC=C:\FOLDER1\FOLDER2
SET DEST=V:\FOLDER1
FOR /D %%d in (%SRC%\*) do xcopy /S /I /y /exclude:%SRC%\exclude.txt %%d V:\FOLDER1\%%~nxd
Basically this script should copy some of the subfolders of C:\FOLDER1\FOLDER2 (excluded.txt contains a list of directories to exclude) and its content to the destination. However when I run the scripts, altough no errors are thrown, NO FILES OR FOLDERS get copied. What am I doing wrong?
Interestingly if I run the following script INSIDE FOLDER2, everything procedes as expected.
FOR /D %%A in (*) DO xcopy /S /I /y /exclude:exclude.txt %%A V:\FOLDER1\%%A
xcopy "C:\FOLDER1\FOLDER2" "V:\FOLDER1" /e /i /y
You mention nothing about excluding any folders.
I’m trying to copy a subfolder of one folder into a number of other folders with unknown names. The intention ist to backup the source file of a program in all employees folders who use it. If the programs folder isn’t found in an employees folder, nothing should be done. This looks as follows:
Source:
F:\Users\myFolder\programFolder\Sourcefolder
Target:
F:\Users\anotherOnesFolder\programFolder\Sourcefolder
So my idea was to do the following:
xcopy "F:\Users\myFolder\programFolder\Sourcefolder" "F:\Users\*\programFolder\Sourcefolder" /e /y
But this wildcard doesn’t seem to work. I’ve found a lot about wildcards at the end of the path, but that doesn’t apply here.
for /d %%d in ("F:\Users\*") do (
if /i not "%%~nxd"=="myFolder" if exist "%%~fd\folder\programFolder\Sourcefolder" (
robocopy "F:\Users\myFolder\programFolder\Sourcefolder" "%%~fd\folder\programFolder\Sourcefolder" * /mir
)
)
for /f %a in ('dir /ad /b "F:\Users*"') do (
xcopy F:\Users\myFolder\programFolder\Sourcefolder "%~dpfa\folder\programFolder\Sourcefolder" /e /y
)
I'd like a batch script in Windows with which I can copy one directory to another. If this directory already exists, and then for each file that already exists in both with the same name and location, it should be overwritten, if it does not exists, it should just be added.
In the end it should be a batch script to which I can pass 2 arguments, source & destination.
In your batch file do this
set source=C:\Users\Habib\test
set destination=C:\Users\Habib\testdest\
xcopy %source% %destination% /y
If you want to copy the sub directories including empty directories then do:
xcopy %source% %destination% /E /y
If you only want to copy sub directories and not empty directories then use /s like:
xcopy %source% %destination% /s /y
It seems that the latest function for this in windows 7 is robocopy.
Usage example:
robocopy <source> <destination> /e /xf <file to exclude> <another file>
/e copies subdirectories including empty ones, /xf excludes certain files from being copied.
More options here: http://technet.microsoft.com/en-us/library/cc733145(v=ws.10).aspx
Have you considered using the "xcopy" command?
The xcopy command will do all that for you.
Try this:
xcopy %1 %2 /y /e
The %1 and %2 are the source and destination arguments you pass to the batch file. i.e. C:\MyBatchFile.bat C:\CopyMe D:\ToHere
Just use xcopy /y source destination
I need to copy a set of DLL and PDB files from a set of folders recursively into another folder. I don't want to recreate the folder hierarchy in the target folder.
I want to use built in Windows tools, e.g. DOS commands.
mkdir targetDir
for /r %x in (*.dll, *pdb) do copy "%x" targetDir\
Use /Y at the end of the above command if you are copying multiple files and don't want to keep answering "Yes".
command XCOPY
example of copying folder recursively:
mkdir DestFolder
xcopy SrcFolder DestFolder /E
(as stated below in the comment following WIKI that command was made available since DOS 3.2)
Make sure that you have the quotes right if you have spaces in your path.
This is my postbuild event for my TFS build server (that is why there is "%%"). I needed all the test files to be copied over.
if not exist "$(TargetDir)..\SingleFolderOutput" mkdir -p "$(TargetDir)..\SingleFolderOutput"
for /r **%%x** in (*.dll, *.pdb, *.xml, *.xaml, *.exe, *.exe.config) do xcopy **"%%x"** "$(TargetDir)..\SingleFolderOutput" /Y
For gathering PBD files I end up with this:
cmd /q /c for /R "<your_source_folder>" %f in (*.pdb) do xcopy "%f" "<your_destination_folder>" /I /Y
Note: must be two percent chars, if you use for /r from cmd-file:
for /r %%x in (*.dll, *pdb) do copy "%%x" targetDir\
#echo off
if %1'==' goto usage
if %2'==' goto usage
if %3'==' goto usage
for /D %%F in (%1\*) do xcopy %%F\%2 %3 /D /Y
for /D %%F in (%1\*.) do call TreeCopy %%F %2 %3
goto end
:usage
#echo Usage: TreeCopy [Source folder] [Search pattern] [Destination folder]
#echo Example: TreeCopy C:\Project\UDI *.xsd C:\Project\UDI\SOA\Deploy\Metadata
:end
I'm not aware of any command line tools that do this directly, but you could create a batch script to loop through sub folders, and copy the files you need.
However you may end up with files with duplicate filenames if you place them all in the same folder.