0

I need to copy folder and its contents to target folder Using Batch Scripting.

For Example , we have folder named "ParentFolder" and inside this folder we have "Child1" folder and inside this i have a text file.

Target folder is named as "Targetfolder"

I want to 1st check if the subfolder of "Parentfolder" is "Child1" folder and then copy the whole folder "Child1" to "Targetfolder"

EDIT - Added code from comment

@echo on
set FOLDER1=c:\Temp\FOLDER1
set FOLDER2=c:\Temp\FOLDER2
if exist %FOLDER1% ( xcopy /Q /D /S /V %FOLDER1% %FOLDER2% )
:END 
7
  • Show us what code you have so far and then we can help you. Commented Dec 6, 2012 at 14:08
  • @echo on set FOLDER1=c:\Temp\FOLDER1 set FOLDER2=c:\Temp\FOLDER2 if exist %FOLDER1% ( xcopy /Q /D /S /V %FOLDER1% %FOLDER2% ) :END I want only selected folders inside FOLDER1, FOLDER1 has several folders Commented Dec 6, 2012 at 14:11
  • Thanku Bali C for helping with editing :) Commented Dec 6, 2012 at 15:42
  • Folder1 is parent folder Folder2 is target folder Commented Dec 7, 2012 at 3:18
  • So, what isn't working for you? I'm not clear on what your question is. Commented Dec 7, 2012 at 15:24

1 Answer 1

1

Just to clarify, you want to copy the folder Parent (Child 1, Child 2) into Target ( Empty ) so that the resulting copy becomes Target ( Parent ( Child 1, Child 2) )?

If so then you need to add the parent name to the target path because xcopy only copies the contents of the source directory into the specified target directory. Be sure to have a backslash at the end of the target path to signify that it is a directory and not a file. Else you will be prompted.

@echo on
set SOURCENAME=FOLDER1
set FOLDER1=c:\Temp\%SOURCENAME%
set FOLDER2=c:\Temp\FOLDER2
if exist %FOLDER1% ( xcopy /Q /D /S /V %FOLDER1% %FOLDER2%\%SOURCENAME%\ )
:END 
Sign up to request clarification or add additional context in comments.

1 Comment

:Thanku fr trying the solution :) , I wanted ` target ( Child1,Child2)`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.