Find the name of the duplicate folders and create a list with the path

Viewed 27

I try to make a textfile with path
To find duplicate folders/subfolders name inside a root path (for example I start from Z:\METALAREA COLLECTION\) I test with this

@echo ON
SETLOCAL EnableDelayedExpansion
for /R /D %%# in (*) do (
    echo "%%~n#">>"C:\Users\Peter\Desktop\text.txt"
)

and I get a textfile formatted in this very bad way

"A"
"# aggiornamenti"
"Abamath & Tahazu - Abamath_Tahazu [split]"
"Abamath & Tahazu - Abamath_Tahazu [split]"
"★"
"beta"
"★ Hekel - Waar de wind fluistert in de nacht, luister ik ★"
"★ Hekel - Waar de wind fluistert in de nacht, luister ik ★"

But I want a textfile formatted in this way

Abamath & Tahazu - Abamath_Tahazu [split]
Z:\METALAREA COLLECTION\ARCHIVE\A
Z:\METALAREA COLLECTION\# aggiornamenti

★ Hekel - Waar de wind fluistert in de nacht, luister ik ★
Z:\METALAREA COLLECTION\ARCHIVE\★
Z:\METALAREA COLLECTION\alfa\beta

Powershell solutions are good accepted because I have many folders with unicode or strange characters

1 Answers

dir /s /b /r /ad %root% (why you using /d? okay I ignore it)

if dosbatch (but with powershell; you can try cscript.exe for vbs/wsh/jscript):

  • make list (dir /b /s /r /ad & tmpfile)
  • reverse characters (powershell.exe; unicode requires check [char] for 2 and 1 chars in cycle)
  • sort.exe
  • in cycle check for /f %%s in ('type "tmpfile"') do set _t_s=%%s&call :sv_for_next
  • :sv_for_next get tmpv=%~1 from call :argv_first "%_t_s:\=" "%"
  • check like findstr /b /i /c:"%tmpv%\" | find /v "%tmpv%" //it's contained ':disk' (secure)
  • from ^step make list (tmpfile2) with folders for tmpv to print tmpv and directories after 're-reverse'

good luck )

also you can use stricted system (rules) for directories naming ("subdir" levels and/or another methods)

Related