Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have many files scattered through multiple directories in a hierarchical fashion. I have some of these files copied to a single directory without all the subdirectories. I need a way to update all the original files from the single linear directory of files.

e.g.,

A files:

C:\dir1\dira\file1
C:\dir1\dira\file2
C:\dir1\dirb\file3
C:\dir1\dirc\file4
D:\dir2\dira\file5

and

B files

E:\dir\file1
E:\dir\file2
E:\dir\file3
E:\dir\file4
E:\dir\file5

The B files have been modified and I need to "push" the modifications to the A files(only the ones that have the same file name).

e.g., E:\dir\file1 copied to C:\dir1\dira\file1 etc...

It's a rather easy process and I probably could write a batch file but is there any software that does this specifically?

share|improve this question
    
Please remember to specify the operating system you use. –  terdon Sep 1 '12 at 23:15
add comment

2 Answers

If i've understood the problem correctly, it is to merge updated files from one directory to another directory which contains the original files and others which should not be touched.

In order of ease of use, these tools have Windows ports: Unison (GUI available), Rsync, "diff & patch".

share|improve this answer
    
His folder structure changed. He would have to diff against each folder and exclude new files. Which would require a script –  RobertMaysJr Sep 2 '12 at 3:16
    
The problem is not "mirroring" the data structure or updating only existing files. It is dealing with the "from" directory as being flat. All the programs I to do this sort of thing compare the files based on their full paths. In this case I want to compare only there filenames(and not paths). C:\root dir(to)\somepath\filea should be treated as the same as D:\root dir(from)\filea. I'll just write a batch file to do it. Shouldn't be that difficult. –  AbstractDissonance Sep 2 '12 at 12:03
add comment

Here is a batch file method I just came up with. It seems to work fine. It could be improved(command line args, etc...) I'll leave that up to someone else...

One needs to change 3 things to make it work: The two directories that are involved in copying and the extension to update from(it could just be .).

The action of the program is:

for each file in C:\root dir 1\*\*.ext, the file will be updated from the file found in C:\root dir 2\*.ext. (note the first is recursive and the second is flat) (The comparison is purely based on the filename. If a file with the same name is found in multiple places in the root dir 1 they all will be updated with the same file from the flat dir)

@echo off
setlocal enableextensions
SETLOCAL EnableDelayedExpansion


set OLDDIR=%CD%
set FLATDIR=C:\Root Dir 1(Hierarchical dir)\
cd /D "C:\Root Dir 2(Flat dir)"
for /r %%q in (*.ext) do (
    cd "%%~dpq"
    if exist "!FLATDIR!%%~nxq" (
        echo Updating %%~dpnxq
        copy /Y /B "!FLATDIR!%%~nxq" "%%~dpnxq" > nul
    )
)


cd /d %OLDDIR%
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.