Solved Batch Script to copy a subfolder to another folder using the

December 6, 2012 at 07:50:30
Specs: Windows 7
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" is "Child1" folder and then copy the whole folder "Child1" to "Targetfolder"

this is what i have done so far but i am getting both child1 and child2 folder .

@echo on
set FOLDER1=c:\Temp\FOLDER1
set FOLDER2=c:\Temp\FOLDER2
if exist %FOLDER1% ( xcopy /Q /D /S /V %FOLDER1% %FOLDER2% )
:END 


See More: Batch Script to copy a subfolder to another folder using the

Report •

#1
December 6, 2012 at 14:13:05
In your script code that you have posted, do FOLDER1 and FOLDER2 represent Child1 and Child2 in your example above or are they supposed to be ParentFolder and TargetFolder?

-----
IT Desktop & Network Consultant - MOS Master Certified, MCP, MCSA, MCITP - Windows 7, CCNA Certificate Pending, A+, Network +

::geek::


Report •

#2
December 6, 2012 at 19:12:49
@SongCloud ,sorry i will add more detail now...
FOLDER1 is PARENTFOLDER
FOLDER2 is TARGETFOLDER

FOLDER1 has two folders CHILD1 and CHILD2

so before copying i have to check weather the FOLDER1 contains CHILD1 and then copy the whole CHILD1 folder to FOLDER2

I am new to batch script


Report •

#3
December 7, 2012 at 17:49:09
✔ Best Answer
No problems. We all have to start somewhere. :)

I'm just trying to get a full overview.

You have 2 subfolders within FOLDER1 (PARENTFOLDER). These are named CHILD1 and CHILD2. Each of these 2 subfolders contains 1 or more text files and perhaps other subfolders as well. You also have a folder named FOLDER2 (TARGETFOLDER) which is where to want to copy one of these subfolders to.

Now, in your script you want to check and see if the CHILD1 folder exists in FOLDER1.

For this, you would use something like the following:

@echo off
set ParentDir=C:\temp\FOLDER1\
set TargetDir=C:\temp\FOLDER2\
set ChildFolder=CHILD1
if exist %ParentDir%%ChildFolder%\. xcopy /Q /S /V %ParentDir%%ChildFolder%\*.* %TargetDir%%ChildFolder%\*.*

So as you can see, you were very close in your original script, just had to make some minor tweaks.

Please let me know if you have any questions. :)

-----
IT Desktop & Network Consultant - MOS Master Certified, MCP, MCSA, MCITP - Windows 7, CCNA Certificate Pending, A+, Network +

::geek::


Report •

Related Solutions

#4
December 8, 2012 at 22:14:49
@SongCloud : Thanks alot fr d solution :) thanks again fr understanding my problem , it works perfectly fine :)

Report •

Ask Question