By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,708 Members | 2,080 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,708 IT Pros & Developers. It's quick & easy.

Batch Script To Copy A Subfolder To Another Directory

P: 3
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" "Child2" folders and inside this i have a text file.
Target folder is named as "Targetfolder"
I want to 1st check if the subfolder of "Parentfolder" has "Child1" folder in it and then copy this folder "Child1" and its contents to "Targetfolder"
this is what i have done so far but i am getting both child1 and child2 folder .

Expand|Select|Wrap|Line Numbers
  1. @echo on
  2. set FOLDER1=c:\Temp\FOLDER1
  3. set FOLDER2=c:\Temp\FOLDER2
  4. if exist %FOLDER1% ( xcopy /Q /D /S /V %FOLDER1% %FOLDER2% )
  5. :END
Dec 6 '12 #1
Share this Question
Share on Google+
5 Replies


Rabbit
Expert Mod 10K+
P: 12,369
I see no references in your script to these Child1, Child2, and TargetFolder folders that you refer to in your description of the problem.
Dec 6 '12 #2

zmbd
Expert Mod 5K+
P: 5,397
You might want to look at a primer for batch files A Windows Batch File Programming Primer

Also, "%FOLDER1%" is not set.
Dec 6 '12 #3

P: 3
I will have to search folder1 to find id child1 exists ,and if it exist i ve to copt chils folder including its contents into another folder.

i am new to batch scripting pls help
Dec 7 '12 #4

P: 3
Sry, adding more detail

FOLDER1 is parent folder
and folder2 is target folder
Dec 7 '12 #5

zmbd
Expert Mod 5K+
P: 5,397
I gave you the link to the tutorial, it has everything you need to solve the problem.

BYTES is not a code writing nor homework service. Rabbit and my self have pointed out several errors that you need to fix and have given you a tool/reference.

If you will rework and repost your efforts someone here may provide "Information, Clarification, and/or Correction"
Dec 7 '12 #6

Post your reply

Sign in to post your reply or Sign up for a free account.