loop through all files in folder, check if first part of filename matches any files in a diff folder-move if...












0

















I have 75,000 files for a karaoke system. For each song there's the music (.mp3) and the lyrics (.cdg). So, for each song there are two files.



Artist - SongName [Karaoke Brand1].mp3
Artist - SongName [Karaoke Brand1].cdg


The issue is that some songs have many versions (5-10). Brand1 is the best, so I've just used standard windows search to filter all files of that brand and cut them and pasted them manually which gave me 25,000 files in the new curated older.



But there are a lot of songs in the original folder that Brand1 doesn't have a version of. I prefer Brand2 and Brand3 in this case, but not every song is done by both. Regardless every song is at least done by one or the other.



I want to loop through all remaining MP3 files in (no need to look at ALL since the .cdgs are the same name with a different extension):



"D:/Karaoke/All" 


and and take the filename BEFORE the square brackets [wildcard?] and see if I already have a version of it in:



"D:/Karaoke/Curated"


If there is do nothing and move to next file.



If there isn't move Brand2 if it exists (full filename .mp3 AND .cdg) to D:/Karaoke/Curated.



If Brand2 doesn't exist, see if Brand3 does and use that one instead



The file naming is the same for all Brands, just the text inside the brackets [Brand] will be different.



EDIT
what i've come up with so far



            @echo off
setlocal enabledelayedexpansion
for %%i in (*.mp3) do (
for /f "tokens=1 delims=[" %%a in ("%%i") DO (
REM get "checkable name first"
REM echo %%a
set checkName=%%a
REM echo !checkName!
)
echo !checkName!
)
exit









share|improve this question




















  • 2





    Please note that Stack OverFlow is not a free code-writing service.

    – double-beep
    Jan 3 at 10:21











  • i know what Stack OverFlow is and isnt. I help people daily in game dev discords and forums. I needed a bit of help for a personal project and thought it would be simple for a one time script to just do it in windows. thanks anyway then. I'll work it out myself. not a friendly bunch here huh. happy new year

    – Carver S
    Jan 3 at 11:01
















0

















I have 75,000 files for a karaoke system. For each song there's the music (.mp3) and the lyrics (.cdg). So, for each song there are two files.



Artist - SongName [Karaoke Brand1].mp3
Artist - SongName [Karaoke Brand1].cdg


The issue is that some songs have many versions (5-10). Brand1 is the best, so I've just used standard windows search to filter all files of that brand and cut them and pasted them manually which gave me 25,000 files in the new curated older.



But there are a lot of songs in the original folder that Brand1 doesn't have a version of. I prefer Brand2 and Brand3 in this case, but not every song is done by both. Regardless every song is at least done by one or the other.



I want to loop through all remaining MP3 files in (no need to look at ALL since the .cdgs are the same name with a different extension):



"D:/Karaoke/All" 


and and take the filename BEFORE the square brackets [wildcard?] and see if I already have a version of it in:



"D:/Karaoke/Curated"


If there is do nothing and move to next file.



If there isn't move Brand2 if it exists (full filename .mp3 AND .cdg) to D:/Karaoke/Curated.



If Brand2 doesn't exist, see if Brand3 does and use that one instead



The file naming is the same for all Brands, just the text inside the brackets [Brand] will be different.



EDIT
what i've come up with so far



            @echo off
setlocal enabledelayedexpansion
for %%i in (*.mp3) do (
for /f "tokens=1 delims=[" %%a in ("%%i") DO (
REM get "checkable name first"
REM echo %%a
set checkName=%%a
REM echo !checkName!
)
echo !checkName!
)
exit









share|improve this question




















  • 2





    Please note that Stack OverFlow is not a free code-writing service.

    – double-beep
    Jan 3 at 10:21











  • i know what Stack OverFlow is and isnt. I help people daily in game dev discords and forums. I needed a bit of help for a personal project and thought it would be simple for a one time script to just do it in windows. thanks anyway then. I'll work it out myself. not a friendly bunch here huh. happy new year

    – Carver S
    Jan 3 at 11:01














0












0








0










I have 75,000 files for a karaoke system. For each song there's the music (.mp3) and the lyrics (.cdg). So, for each song there are two files.



Artist - SongName [Karaoke Brand1].mp3
Artist - SongName [Karaoke Brand1].cdg


The issue is that some songs have many versions (5-10). Brand1 is the best, so I've just used standard windows search to filter all files of that brand and cut them and pasted them manually which gave me 25,000 files in the new curated older.



But there are a lot of songs in the original folder that Brand1 doesn't have a version of. I prefer Brand2 and Brand3 in this case, but not every song is done by both. Regardless every song is at least done by one or the other.



I want to loop through all remaining MP3 files in (no need to look at ALL since the .cdgs are the same name with a different extension):



"D:/Karaoke/All" 


and and take the filename BEFORE the square brackets [wildcard?] and see if I already have a version of it in:



"D:/Karaoke/Curated"


If there is do nothing and move to next file.



If there isn't move Brand2 if it exists (full filename .mp3 AND .cdg) to D:/Karaoke/Curated.



If Brand2 doesn't exist, see if Brand3 does and use that one instead



The file naming is the same for all Brands, just the text inside the brackets [Brand] will be different.



EDIT
what i've come up with so far



            @echo off
setlocal enabledelayedexpansion
for %%i in (*.mp3) do (
for /f "tokens=1 delims=[" %%a in ("%%i") DO (
REM get "checkable name first"
REM echo %%a
set checkName=%%a
REM echo !checkName!
)
echo !checkName!
)
exit









share|improve this question


















I have 75,000 files for a karaoke system. For each song there's the music (.mp3) and the lyrics (.cdg). So, for each song there are two files.



Artist - SongName [Karaoke Brand1].mp3
Artist - SongName [Karaoke Brand1].cdg


The issue is that some songs have many versions (5-10). Brand1 is the best, so I've just used standard windows search to filter all files of that brand and cut them and pasted them manually which gave me 25,000 files in the new curated older.



But there are a lot of songs in the original folder that Brand1 doesn't have a version of. I prefer Brand2 and Brand3 in this case, but not every song is done by both. Regardless every song is at least done by one or the other.



I want to loop through all remaining MP3 files in (no need to look at ALL since the .cdgs are the same name with a different extension):



"D:/Karaoke/All" 


and and take the filename BEFORE the square brackets [wildcard?] and see if I already have a version of it in:



"D:/Karaoke/Curated"


If there is do nothing and move to next file.



If there isn't move Brand2 if it exists (full filename .mp3 AND .cdg) to D:/Karaoke/Curated.



If Brand2 doesn't exist, see if Brand3 does and use that one instead



The file naming is the same for all Brands, just the text inside the brackets [Brand] will be different.



EDIT
what i've come up with so far



            @echo off
setlocal enabledelayedexpansion
for %%i in (*.mp3) do (
for /f "tokens=1 delims=[" %%a in ("%%i") DO (
REM get "checkable name first"
REM echo %%a
set checkName=%%a
REM echo !checkName!
)
echo !checkName!
)
exit






loops batch-file move






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 11:12







Carver S

















asked Jan 3 at 10:16









Carver SCarver S

215




215








  • 2





    Please note that Stack OverFlow is not a free code-writing service.

    – double-beep
    Jan 3 at 10:21











  • i know what Stack OverFlow is and isnt. I help people daily in game dev discords and forums. I needed a bit of help for a personal project and thought it would be simple for a one time script to just do it in windows. thanks anyway then. I'll work it out myself. not a friendly bunch here huh. happy new year

    – Carver S
    Jan 3 at 11:01














  • 2





    Please note that Stack OverFlow is not a free code-writing service.

    – double-beep
    Jan 3 at 10:21











  • i know what Stack OverFlow is and isnt. I help people daily in game dev discords and forums. I needed a bit of help for a personal project and thought it would be simple for a one time script to just do it in windows. thanks anyway then. I'll work it out myself. not a friendly bunch here huh. happy new year

    – Carver S
    Jan 3 at 11:01








2




2





Please note that Stack OverFlow is not a free code-writing service.

– double-beep
Jan 3 at 10:21





Please note that Stack OverFlow is not a free code-writing service.

– double-beep
Jan 3 at 10:21













i know what Stack OverFlow is and isnt. I help people daily in game dev discords and forums. I needed a bit of help for a personal project and thought it would be simple for a one time script to just do it in windows. thanks anyway then. I'll work it out myself. not a friendly bunch here huh. happy new year

– Carver S
Jan 3 at 11:01





i know what Stack OverFlow is and isnt. I help people daily in game dev discords and forums. I needed a bit of help for a personal project and thought it would be simple for a one time script to just do it in windows. thanks anyway then. I'll work it out myself. not a friendly bunch here huh. happy new year

– Carver S
Jan 3 at 11:01












1 Answer
1






active

oldest

votes


















1
















Here is a possible solution according to your requirements:



@echo off

cd /d "D:KaraokeAll"
for %%A IN ("*.mp3") do (
for /f "delims=" %%B IN ("%%~nA") do (
dir /A "D:KaraokeCurated%%B*" >nul 2>&1
if errorlevel 1 (
if exist "%%B[Karaoke Brand2].mp3" (
move "%%B[Karaoke Brand2].*" "D:KaraokeCurated"
) else (
if exist "%%B[Karaoke Brand3].mp3" (
move "%%B[Karaoke Brand3].*" "D:KaraokeCurated"
)
)
)
)
)





share|improve this answer





















  • 1





    The dir /b D:KaraokeCurated | findstr /c:"%%B" will without need scan the whole dir and invoke a 2nd cmd through the pipe. Simply use instead dir /b "D:KaraokeCurated%%B*" >Nul 2>&1 this will equally trigger the errorlevel. You might as well append |findstr /i "Brand[23] to check if one of the desired alternative brands exists.

    – LotPings
    Jan 3 at 11:59






  • 1





    @LotPings Good idea for the first one! But for the second, the owner has mentioned that he has moved all *Brand1* files to this directory. Thank you very much.

    – double-beep
    Jan 3 at 12:13











  • rgr. update works great. thanks again guys.

    – Carver S
    Jan 3 at 12:43











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54020253%2floop-through-all-files-in-folder-check-if-first-part-of-filename-matches-any-fi%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1
















Here is a possible solution according to your requirements:



@echo off

cd /d "D:KaraokeAll"
for %%A IN ("*.mp3") do (
for /f "delims=" %%B IN ("%%~nA") do (
dir /A "D:KaraokeCurated%%B*" >nul 2>&1
if errorlevel 1 (
if exist "%%B[Karaoke Brand2].mp3" (
move "%%B[Karaoke Brand2].*" "D:KaraokeCurated"
) else (
if exist "%%B[Karaoke Brand3].mp3" (
move "%%B[Karaoke Brand3].*" "D:KaraokeCurated"
)
)
)
)
)





share|improve this answer





















  • 1





    The dir /b D:KaraokeCurated | findstr /c:"%%B" will without need scan the whole dir and invoke a 2nd cmd through the pipe. Simply use instead dir /b "D:KaraokeCurated%%B*" >Nul 2>&1 this will equally trigger the errorlevel. You might as well append |findstr /i "Brand[23] to check if one of the desired alternative brands exists.

    – LotPings
    Jan 3 at 11:59






  • 1





    @LotPings Good idea for the first one! But for the second, the owner has mentioned that he has moved all *Brand1* files to this directory. Thank you very much.

    – double-beep
    Jan 3 at 12:13











  • rgr. update works great. thanks again guys.

    – Carver S
    Jan 3 at 12:43
















1
















Here is a possible solution according to your requirements:



@echo off

cd /d "D:KaraokeAll"
for %%A IN ("*.mp3") do (
for /f "delims=" %%B IN ("%%~nA") do (
dir /A "D:KaraokeCurated%%B*" >nul 2>&1
if errorlevel 1 (
if exist "%%B[Karaoke Brand2].mp3" (
move "%%B[Karaoke Brand2].*" "D:KaraokeCurated"
) else (
if exist "%%B[Karaoke Brand3].mp3" (
move "%%B[Karaoke Brand3].*" "D:KaraokeCurated"
)
)
)
)
)





share|improve this answer





















  • 1





    The dir /b D:KaraokeCurated | findstr /c:"%%B" will without need scan the whole dir and invoke a 2nd cmd through the pipe. Simply use instead dir /b "D:KaraokeCurated%%B*" >Nul 2>&1 this will equally trigger the errorlevel. You might as well append |findstr /i "Brand[23] to check if one of the desired alternative brands exists.

    – LotPings
    Jan 3 at 11:59






  • 1





    @LotPings Good idea for the first one! But for the second, the owner has mentioned that he has moved all *Brand1* files to this directory. Thank you very much.

    – double-beep
    Jan 3 at 12:13











  • rgr. update works great. thanks again guys.

    – Carver S
    Jan 3 at 12:43














1












1








1









Here is a possible solution according to your requirements:



@echo off

cd /d "D:KaraokeAll"
for %%A IN ("*.mp3") do (
for /f "delims=" %%B IN ("%%~nA") do (
dir /A "D:KaraokeCurated%%B*" >nul 2>&1
if errorlevel 1 (
if exist "%%B[Karaoke Brand2].mp3" (
move "%%B[Karaoke Brand2].*" "D:KaraokeCurated"
) else (
if exist "%%B[Karaoke Brand3].mp3" (
move "%%B[Karaoke Brand3].*" "D:KaraokeCurated"
)
)
)
)
)





share|improve this answer

















Here is a possible solution according to your requirements:



@echo off

cd /d "D:KaraokeAll"
for %%A IN ("*.mp3") do (
for /f "delims=" %%B IN ("%%~nA") do (
dir /A "D:KaraokeCurated%%B*" >nul 2>&1
if errorlevel 1 (
if exist "%%B[Karaoke Brand2].mp3" (
move "%%B[Karaoke Brand2].*" "D:KaraokeCurated"
) else (
if exist "%%B[Karaoke Brand3].mp3" (
move "%%B[Karaoke Brand3].*" "D:KaraokeCurated"
)
)
)
)
)






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 3 at 12:29









LotPings

19.9k61633




19.9k61633










answered Jan 3 at 11:05









double-beepdouble-beep

3,05141331




3,05141331








  • 1





    The dir /b D:KaraokeCurated | findstr /c:"%%B" will without need scan the whole dir and invoke a 2nd cmd through the pipe. Simply use instead dir /b "D:KaraokeCurated%%B*" >Nul 2>&1 this will equally trigger the errorlevel. You might as well append |findstr /i "Brand[23] to check if one of the desired alternative brands exists.

    – LotPings
    Jan 3 at 11:59






  • 1





    @LotPings Good idea for the first one! But for the second, the owner has mentioned that he has moved all *Brand1* files to this directory. Thank you very much.

    – double-beep
    Jan 3 at 12:13











  • rgr. update works great. thanks again guys.

    – Carver S
    Jan 3 at 12:43














  • 1





    The dir /b D:KaraokeCurated | findstr /c:"%%B" will without need scan the whole dir and invoke a 2nd cmd through the pipe. Simply use instead dir /b "D:KaraokeCurated%%B*" >Nul 2>&1 this will equally trigger the errorlevel. You might as well append |findstr /i "Brand[23] to check if one of the desired alternative brands exists.

    – LotPings
    Jan 3 at 11:59






  • 1





    @LotPings Good idea for the first one! But for the second, the owner has mentioned that he has moved all *Brand1* files to this directory. Thank you very much.

    – double-beep
    Jan 3 at 12:13











  • rgr. update works great. thanks again guys.

    – Carver S
    Jan 3 at 12:43








1




1





The dir /b D:KaraokeCurated | findstr /c:"%%B" will without need scan the whole dir and invoke a 2nd cmd through the pipe. Simply use instead dir /b "D:KaraokeCurated%%B*" >Nul 2>&1 this will equally trigger the errorlevel. You might as well append |findstr /i "Brand[23] to check if one of the desired alternative brands exists.

– LotPings
Jan 3 at 11:59





The dir /b D:KaraokeCurated | findstr /c:"%%B" will without need scan the whole dir and invoke a 2nd cmd through the pipe. Simply use instead dir /b "D:KaraokeCurated%%B*" >Nul 2>&1 this will equally trigger the errorlevel. You might as well append |findstr /i "Brand[23] to check if one of the desired alternative brands exists.

– LotPings
Jan 3 at 11:59




1




1





@LotPings Good idea for the first one! But for the second, the owner has mentioned that he has moved all *Brand1* files to this directory. Thank you very much.

– double-beep
Jan 3 at 12:13





@LotPings Good idea for the first one! But for the second, the owner has mentioned that he has moved all *Brand1* files to this directory. Thank you very much.

– double-beep
Jan 3 at 12:13













rgr. update works great. thanks again guys.

– Carver S
Jan 3 at 12:43





rgr. update works great. thanks again guys.

– Carver S
Jan 3 at 12:43




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54020253%2floop-through-all-files-in-folder-check-if-first-part-of-filename-matches-any-fi%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas