-1

I have a question. Is it possibile in batch language to search in folder a part of name that is same like another file and display it.For example i got folder with files :

ggggggsss.mp3 
ddddddeee.mp3 
ddddddff.mp3 
ssssssddd.mp3 
aaaaasssss.mp3
11111ssdas.mp3 
11111dddd.mp3 
...

I need to display in cmd only names of files

ddddddeee
ddddddff

and

11111ssdas
11111dddddd

Because the first six letter are the same. Could someone help me with this problem?

DavidPostill
  • 7,734
  • 9
  • 41
  • 60
szakalaka
  • 1
  • 3
  • Did you start writing something already ? what platform are you tagetting , windows ? – Gar Aug 12 '16 at 17:12
  • Yes, in windows, no i not start yet, i'm just trying to figure out if it's possible – szakalaka Aug 12 '16 at 17:16
  • I highly doubt this could be done with pure DOS commands. – Gar Aug 12 '16 at 17:17
  • You can grab substrings of file names and compare them. Or you can look through tokens of the filenames, but it depends on how complex your wish your comparisons to be here. – ManoDestra Aug 12 '16 at 17:26
  • 2
    The answer to your question is: Yes!. However, you should post a list with several file names and the desired output, because your description is confusing... Please, modify the original question; do NOT post additional data in comments! – Aacini Aug 12 '16 at 17:52
  • How can i grab substrings of file names and compare them? – szakalaka Aug 12 '16 at 20:07
  • The asker fully changed the question. Now claiming in comment: _this program need to scan all filenames without default pattern_, which contradicts the original question. Request to Hold as too broad and unclear. – sambul35 Aug 13 '16 at 22:26

1 Answers1

0

Save this script to test.bat and run from open Cmd Prompt. Replace dir value with path to your folder with .mp3 files:

@echo off
setlocal enabledelayedexpansion
set "dir=%userprofile%\music"
set "pattern1=dddddd" & set "pattern2=11111"
pushd "%dir%"
FOR %%G IN (*.mp3) DO ( set song=%%G
    if "!song:~0,6!"=="%pattern1%" echo %%G)
echo/
FOR %%G IN (*.mp3) DO ( set song=%%G
    if "!song:~0,5!"=="%pattern2%" echo %%G)
popd
exit /b

See also Extract Substrings.

sambul35
  • 1,058
  • 14
  • 22
  • Thanks! You are awesome! But i have last problem.. I got a thousend of files and i dont know which substring is duplicated, this program need to scan all filenames without default pattern – szakalaka Aug 13 '16 at 18:45
  • Its impossible to group files without setting a pattern size, like 1 to 10+ digits or letters. Otherwise the files will be sorted by alphabet but not grouped. Identifying an unknown match pattern is a separate task, you must ask a separate question. – sambul35 Aug 13 '16 at 23:11