Compare 2 folder and rename one folder name based on the oth

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Auryn
Posts: 4
Joined: 15 Jun 2014 17:38

Compare 2 folder and rename one folder name based on the oth

#1 Post by Auryn » 15 Jun 2014 17:52

Hi guys,
i am looking for way to compare 2 folders and rename the files in one folder based on the names in another folder.
Let's have 2 folders named A and B
In folder A there are all files named xxx.yyyy
In folder B there are some files named xxx.yyy and others named xxx.c.yyyy
xxx is always starting from 000 up to 999 in both folders.

I need to check what files in folder B has that ".c" in the name and rename the corresponding file in folder A to have the same ".c" in the name in the same place.

Last note, yyyy is sometimes 3 letters and sometimes 4 letters.

Can we do this with a batch file?? Somebody has some code idea in how to do this??

Thanks

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Compare 2 folder and rename one folder name based on the

#2 Post by foxidrive » 16 Jun 2014 02:03

Give some concrete examples, if you want a concrete batch file. :)

Auryn
Posts: 4
Joined: 15 Jun 2014 17:38

Re: Compare 2 folder and rename one folder name based on the

#3 Post by Auryn » 16 Jun 2014 05:02

Folder A
000.bin
001.ncgr
002.bin
003.nclr

Folder B
000.bin
001.c.ncgr
002.c.bin
003.nclr


After the process, folder A need to have:
000.bin
001.c.ncgr
002.c.bin
003.nclr

It need to be renamed and not copied because even if the files have the same name, it's not said they have the same contenent.

Thanks

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Compare 2 folder and rename one folder name based on the

#4 Post by foxidrive » 16 Jun 2014 06:42

EDITED

Test this:

Code: Select all

@echo off
for /f "delims=" %%a in ('dir "Folder A\*.*" /b /s /a-d ') do (
    for /f "delims=" %%b in ('dir "Folder B\%%~na*%%~xa" /b /a-d 2^>nul ') do ren "%%a" "%%b"
)
 

Auryn
Posts: 4
Joined: 15 Jun 2014 17:38

Re: Compare 2 folder and rename one folder name based on the

#5 Post by Auryn » 17 Jun 2014 01:10

Hi foxidrive, thanks but sadly it's not working, it say that "the system cannot find the file specified." repeatly.

I tried in winVista, but i could test it in win7 if necessary.
I even tried moving it to c:\ and not on the desktop to be sure.
The folders i tried that on had all .bin extentions so it's sure not the extentions messing this up.
I removed the spaces in the names of the folders and in your code naturally.

Any other ideas??

Thanks

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Compare 2 folder and rename one folder name based on the

#6 Post by foxidrive » 17 Jun 2014 02:00

Check my edit in the code above. It's tested.

Auryn
Posts: 4
Joined: 15 Jun 2014 17:38

Re: Compare 2 folder and rename one folder name based on the

#7 Post by Auryn » 17 Jun 2014 05:30

Yeap, at first look it seems to work.

Thanks a lot.

Post Reply