0

I have several files and folders on different directories which I'm quite positive they have been renamed on those other directories with capitalized letters.

I wanted to be able to find those duplicately named files and folders on the different directories and sort them out so I can see and then track them down afterwards.

Something like:

C:\Program Files\hello.txt

C:\WhateverFolder\heLlo.txt

This would be the output of the program or something similar to that.

You guys think it's possible?

mklement0
  • 382,024
  • 64
  • 607
  • 775
Gabriel
  • 65
  • 1
  • 1
  • 9
  • 2
    This may help... http://stackoverflow.com/questions/20248082/binary-compare-all-files-against-all-files-in-a-specified-directory-and-subdire/20248223#20248223 – Mark Setchell Jan 27 '14 at 14:25
  • Unfortunately, no, it didn't help me, sorry :/ Either I'm too much of a "noob" or I couldn't make that work – Gabriel Jan 27 '14 at 15:00

2 Answers2

2
find /directory | awk '{names[gensub(".*/","","g")]++} END { for (name in names) { if (names[name] > 1) { print name } } }' 

Might give you a list of duplicate names (files and folders). That gives you a starting point.

The above assumes gawk, so here is a more general solution which even supports mixed-case filenames, kudos to mklement0 for the idea:

find /directory | awk -F '/' '{names[tolower($NF)]++} END { for (name in names) { if (names[name]>1) { print name }}}'
Community
  • 1
  • 1
Zsolt Botykai
  • 50,406
  • 14
  • 85
  • 110
  • Well, maybe you can solve this now: It says "awk" does not exist. How would I make it exist? – Gabriel Jan 27 '14 at 15:05
  • @Gabriel: Assuming you're on Windows (which your example paths suggest), you need a Unix compatibility layer such as [MSYS](http://www.mingw.org/wiki/MSYS) – mklement0 Jan 27 '14 at 15:20
  • @Zsolt: Beautiful `akw`ery, but (a) you're missing `}}` at the end, and (b) you're assuming `gawk`; a variant of your command that should work on more platforms is: `find /directory | awk -F '/' '{names[$NF]++} END { for (name in names) { if (names[name]>1) { print name }}}'` – mklement0 Jan 27 '14 at 15:28
  • @mklement0: Yes, I am using Windows and thanks for that comment, using the Unix compatibility layer made it easier and accomplishable along with your other comment on what was missing at Zsolt's comment. – Gabriel Jan 27 '14 at 15:36
  • 1
    @Gabriel: Glad to hear it - one other thing to note: the matching is not case-INsensitive, as your question stipulates. To make it so, use `find /directory | awk -F '/' '{names[tolower($NF)]++} END { for (name in names) { if (names[name]>1) { print name }}}' - one caveat there: MSYS currently has no Unicode support, so this won't work with foreign chars. (Curiously, even the `awk` versions on at least a few Unix platforms lack Unicode support.) – mklement0 Jan 27 '14 at 17:31
  • @mklement0 thanks for improving my answer, if you don't mind I had edited your solution to it. – Zsolt Botykai Jan 27 '14 at 18:50
  • @ZsoltBotykai: You're welcome - thanks for updating your answer. – mklement0 Jan 27 '14 at 18:53
0

If Unix-y commands are too much for you, you can get a listing like this and sort it out yourself maybe?

DIR /B /S /L  somefolder
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432