Merge two folders - please help
Moderator: DosItHelp
Merge two folders - please help
Hi Folks,
Im new to this forum and just started working on DOS.. i have a new requirement like,
1. Copy a Folder (Folder 1) which contains sub folders (Folder 2 Folder 3) to a new Location
2. Copy a second Folder (Folder 4) which contains same sub Folders (same folder names Folder 2 and Folder 3) and some additional files
3. And the challenge is in the Destination Folder step 1 and step 2 files should be merged not overwritten
4. Another challenge is the Destination folder name should be dynamically created(lets say using the appended name of Folder 1 and Folder 2)
5. Additionally all these folders are in my network drive.
So please help, i need to give a batch script for the above to my boss by tomorrow. Thanks in Advance.
Eg Scenario.
Folder 1 content i copied to Destination Folder .
Folder 2 content i copied to the same destination folder.
DestinationFolder should contains the Folder 1 and Folder 2 merged content and there are many sub folders with the same name in Folder 1 and 2.
Thanks
Im new to this forum and just started working on DOS.. i have a new requirement like,
1. Copy a Folder (Folder 1) which contains sub folders (Folder 2 Folder 3) to a new Location
2. Copy a second Folder (Folder 4) which contains same sub Folders (same folder names Folder 2 and Folder 3) and some additional files
3. And the challenge is in the Destination Folder step 1 and step 2 files should be merged not overwritten
4. Another challenge is the Destination folder name should be dynamically created(lets say using the appended name of Folder 1 and Folder 2)
5. Additionally all these folders are in my network drive.
So please help, i need to give a batch script for the above to my boss by tomorrow. Thanks in Advance.
Eg Scenario.
Folder 1 content i copied to Destination Folder .
Folder 2 content i copied to the same destination folder.
DestinationFolder should contains the Folder 1 and Folder 2 merged content and there are many sub folders with the same name in Folder 1 and 2.
Thanks
Re: Merge two folders - please help
Requirement as below again..
Source
\\100.X.X.X\Folder1
Source
\\100.X.X.X\Folder10\FolderX
Common Destination
\\100.X.X.X\FolderDestination\Folder1FolderX
This folder should contain the merged (If there are any sub folders with same names) content of Folder1 and FolderX (Including sub folders and all the files)
Source
\\100.X.X.X\Folder1
Source
\\100.X.X.X\Folder10\FolderX
Common Destination
\\100.X.X.X\FolderDestination\Folder1FolderX
This folder should contain the merged (If there are any sub folders with same names) content of Folder1 and FolderX (Including sub folders and all the files)
Re: Merge two folders - please help
Looks like a couple of different requirements.
If your folder FolderX's are named the same, a simple xcopy command will do it unless there are identical file names. For identical names, you'll have to rename something unless you want the files actually merged.
I'm not sure I follow the others requirements completely. Some examples will help.
If your folder FolderX's are named the same, a simple xcopy command will do it unless there are identical file names. For identical names, you'll have to rename something unless you want the files actually merged.
I'm not sure I follow the others requirements completely. Some examples will help.
Re: Merge two folders - please help
If there are any files with the same name it will ask you what to do.
Code: Select all
@echo off
xcopy /s/h/e/k/f/c "\\100.X.X.X\Folder1\*.*" "\\100.X.X.X\FolderDestination\Folder1FolderX\"
xcopy /s/h/e/k/f/c "\\100.X.X.X\Folder10\FolderX\*.*" "\\100.X.X.X\FolderDestination\Folder1FolderX\"
Re: Merge two folders - please help
Thank you both.. i came up with the below script..
@echo off
set Source1=C:\New\Folder1
set Source2=C:\New\Folder2
Set Dest=C:\New\Newfolder
xcopy /s/h/e/k/f/c %Source1%\*.* %Dest%\
xcopy /s/h/e/k/f/c %Source2%\*.* %Dest%\
But the problem is, it overwrites the files in the destination. My intention is to do the merging.
@echo off
set Source1=C:\New\Folder1
set Source2=C:\New\Folder2
Set Dest=C:\New\Newfolder
xcopy /s/h/e/k/f/c %Source1%\*.* %Dest%\
xcopy /s/h/e/k/f/c %Source2%\*.* %Dest%\
But the problem is, it overwrites the files in the destination. My intention is to do the merging.
Re: Merge two folders - please help
The /-y switch causes a prompt to appear on filename clashes
Code: Select all
@echo off
set "Source1=C:\New\Folder1"
set "Source2=C:\New\Folder2"
Set "Dest=C:\New\Newfolder"
xcopy /s/h/e/k/f/c /-y "%Source1%\*.*" "%Dest%\"
xcopy /s/h/e/k/f/c /-y "%Source2%\*.*" "%Dest%\"
Re: Merge two folders - please help
thanks you..Now i am moving to my complete requirement...Trying the below. Gor help from many people. Its working fine if i need to append 2 folder names from two different paths.
@ECHO OFF
Set NasPath=C:\New\Folder1
Set NasFolder=%NasPath%
:GetFolder
Set GetFolderTemp=%NasFolder:*\=%
If Not %GetFolderTemp%==%NasFolder% (
Set NasFolder=%GetFolderTemp%
Goto :GetFolder
)
Exit /B
Set NasPath1=C:\New\Folder2
Set NasFolder1=%NasPath1%
:GetFolder
Set GetFolderTemp1=%NasFolder1:*\=%
If Not %GetFolderTemp1%==%NasFolder1% (
Set NasFolder1=%GetFolderTemp1%
Goto :GetFolder
)
Echo NasPath1=%NasPath1%
Echo NasFolder1=%NasFolder1%
Echo NasPath=%NasPath%
Echo NasFolder=%NasFolder%
Set Dest=C:\New\%NASFOLDER%_%NasFolder1%
ECHO %Dest%
Exit /B
If i have a folder structure like below.
SourceA= Folder1\Folder2\Folder3
SourceB=Folder4\Folder5
And my destination Foldername should be,
Dest=FolderX\FolderX1\Folder2_Folder5
How to achieve this?
@ECHO OFF
Set NasPath=C:\New\Folder1
Set NasFolder=%NasPath%
:GetFolder
Set GetFolderTemp=%NasFolder:*\=%
If Not %GetFolderTemp%==%NasFolder% (
Set NasFolder=%GetFolderTemp%
Goto :GetFolder
)
Exit /B
Set NasPath1=C:\New\Folder2
Set NasFolder1=%NasPath1%
:GetFolder
Set GetFolderTemp1=%NasFolder1:*\=%
If Not %GetFolderTemp1%==%NasFolder1% (
Set NasFolder1=%GetFolderTemp1%
Goto :GetFolder
)
Echo NasPath1=%NasPath1%
Echo NasFolder1=%NasFolder1%
Echo NasPath=%NasPath%
Echo NasFolder=%NasFolder%
Set Dest=C:\New\%NASFOLDER%_%NasFolder1%
ECHO %Dest%
Exit /B
If i have a folder structure like below.
SourceA= Folder1\Folder2\Folder3
SourceB=Folder4\Folder5
And my destination Foldername should be,
Dest=FolderX\FolderX1\Folder2_Folder5
How to achieve this?
Re: Merge two folders - please help
dosmushi wrote:How to achieve this?
What do you want to do? Please describe your aim.
Re: Merge two folders - please help
Yeah, I was a bit confused too. It seemed like an easy xcopy solution, but the conbined foldername requirements aren't clear.foxidrive wrote:dosmushi wrote:How to achieve this?
What do you want to do? Please describe your aim.