Akshay J
Akshay J

Reputation: 5458

Copy all files in a folder (including all sub-folders recursively) into another folder

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

Upvotes: 1

Views: 12640

Answers (1)

Dunny
Dunny

Reputation: 170

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?

Upvotes: 2

Related Questions