![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-10 16:57 |
47,811 topics / 349,897 posts / today 0 new / 48,256 members |
| DOS批处理 & 脚本技术(批处理室) » Let's help use batch processing to find MP3s without accompanying lyrics. |
| Printable Version 3,146 / 13 |
| Floor1 junyee | Posted 2006-10-01 21:17 |
| 中级用户 Posts 112 Credits 253 | |
|
Nowadays, many MP3 players can display lyrics. For normal display, the lyric file (*.lrc) must have the same name as the song file (*.mp3) and be in the same directory.!!!
But it's often difficult for us to find out whether there is a corresponding lyric file. So I made a batch script referring to similar previous posts, although there are many deficiencies.^^ I sincerely ask all seniors for your valuable advice. Suppose the drive letter corresponding to the MP3 is G:\ G:\Music is a special directory for storing songs. Because many current MP3 players can read multiple levels of directories, so categorizing different types of songs into different directories can make using them more convenient. Suppose there are two more directories under G:\Music G:\Music\01 G:\Music\02 The batch script is as follows. @echo off del G:\list.txt>nul 2>nul echo ---G:Music\01 >G:\list.txt cd /d G:\music\01 for %%i in (*.mp3 *.wma) do (if not exist %%~ni.lrc echo %%~ni>>G:\list.txt) echo ---G:Music\02 >>G:\list.txt cd /d G:\Music\02 for %%i in (*.mp3 *.wma) do (if not exist %%~ni.lrc echo %%~ni>>G:\list.txt) notepad G:\list.txt exit It has been tested to work. I'm a newbie. I feel awkward to write so many lines of code for such a simple operation. I hope everyone can help simplify it. If there are any problems, I also sincerely ask everyone to point them out. [ Last edited by junyee on 2006-10-1 at 22:49 ] |
|
| Floor2 pengfei | Posted 2006-10-01 21:45 |
| 银牌会员 Posts 485 Credits 1,218 From 湖南.娄底 | |
|
@echo off
echo _____________________G:Music\01 >G:\list.txt cd /d G:\music\01 for %%i in (*.mp3 *.wma) do if not exist %%~ni.lrc echo %%~ni>>G:\list.txt echo _____________________G:Music\02 >>G:\list.txt cd /d G:\Music\02 for %%i in (*.mp3 *.wma) do if not exist %%~ni.lrc echo %%~ni>>G:\list.txt start G:\list.txt exit The landlord's code is written well!!! I removed del because the line echo ---G:Music\01 >G:\list.txt below will refresh the content. (As long as the file attribute is not read-only!) The two for statements are the nesting of two compound statements, for and if, and parentheses are not needed. The line notepad G:\list.txt is changed to start G:\list.txt because in DOS, to open an application, since the suffixes are all associated, the system will automatically call Notepad to open it. [ Last edited by pengfei on 2006-10-1 at 23:18 ] |
|
| Floor3 namejm | Posted 2006-10-01 22:03 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
Actually, your code is already quite concise. The only thing that can be modified is to optimize some parts of the code. Especially, there is a problem with the line `notepad G:\list.txt`. Once you use this line, the batch processing window will not exit until G:\list.txt is closed, and the exit statement at the end can be omitted. Modify your code as follows:
Just after posting, I found that pengfei has already given the code on the second floor. Hehe, he's really quick. But it's not appropriate to remove the del statement because I don't know the attributes of G:\list.txt. If it's in read-only attribute, the echo redirection to G:\list.txt will not be able to write! So my code still retains the del statement, and adds the /a /f parameters to force deletion, and adds the silent parameter /q; also considering that G:\list.txt may not exist, so uses 2>nul to shield the display of error messages on the screen. [ Last edited by namejm on 2006-10-1 at 22:09 ] |
|
| Floor4 junyee | Posted 2006-10-01 22:35 |
| 中级用户 Posts 112 Credits 253 | |
|
kcOh, I still feel it's not concise enough..
But, is there any way to further simplify the above command? Because echo ---G:Music\01 >>G:\list.txt cd /d G:\music\01 for %%i in (*.mp3 *.wma) do if not exist %%~ni.lrc echo %%~ni>>G:\list.txt echo ---G:Music\02 >>G:\list.txt cd /d G:\Music\02 for %%i in (*.mp3 *.wma) do if not exist %%~ni.lrc echo %%~ni>>G:\list.txt What's done here is repetitive actions with only different directory names. If there are many folders under G:\music, it will be even longer? |
|
| Floor5 namejm | Posted 2006-10-01 23:03 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
You can try the following code (temporarily not considering various possible errors, such as the problem of files with the same name in mp3 format and wma format):
|
|
| Floor6 zh159 | Posted 2006-10-01 23:30 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
|
All folders in the current directory are okay.
Note: Folders should not have spaces or sensitive characters. If you want to distinguish between MP3 format and WMA format, change it to ">>list.txt echo %1\%%i" |
|
| Floor7 NaturalJ0 | Posted 2006-10-01 23:54 |
| 银牌会员 Posts 533 Credits 1,181 | |
|
```
@echo off del/a/f/q list.txt 2>nul & for /f "delims=" %%i in ('dir/s/a-d/b *.mp3 *.wma') do ( if not exist "%%~di%%~pi%%~ni.lrc" echo %%i>>list.txt ) start list.txt ``` I also try [ Last edited by NaturalJ0 on 2006-10-2 at 00:01 ] |
|
| Floor8 pengfei | Posted 2006-10-02 00:21 |
| 银牌会员 Posts 485 Credits 1,218 From 湖南.娄底 | |
|
Everyone's writing is pretty good. I'll also post a section. Traverse each directory under the current directory. List the song names without lyrics and note the directory they are in. The problem of spaces in the path should be handleable. It will also search the current directory, and if there are no files, it will prompt that no files are found...
Moderator namejm said about read-only files, which cannot be written. This is very important, so still choose DEL. If there are two formats of files with the same name in the same directory, this cannot be handled in any way, because there can only be one lrc, so the other format file has to be renamed. For more music types, add according to the current format in the second for statement. [ Last edited by pengfei on 2006-10-2 at 05:34 ] |
|
| Floor9 pengfei | Posted 2006-10-02 02:09 |
| 银牌会员 Posts 485 Credits 1,218 From 湖南.娄底 | |
|
Found the code from user namejm on floor 5. It turns out that you can list matching files in a directory without using dir. Hehe~ Learned something...
The following code has the same function as the one on floor 8, completed with a single for. The speed is also decent! [ Last edited by pengfei on 2006-10-2 at 05:34 ] |
|
| Floor10 无奈何 | Posted 2006-10-02 05:18 |
| 荣誉版主 Posts 356 Credits 1,338 | |
|
Simple command-line display version:
Strictly formatted version: |
|
| Floor11 pengfei | Posted 2006-10-02 08:27 |
| 银牌会员 Posts 485 Credits 1,218 From 湖南.娄底 | |
:sub Found that %%i is reassigned to %1, and it can still use the variable expansion of for..... |
|
| Floor12 vkill | Posted 2006-10-03 08:01 |
| 金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽 | |
|
It would be nice if we could get something like Qianqian Jingting that automatically downloads lyrics.
|
|
| Floor13 yayumyself | Posted 2007-06-21 17:35 |
| 初级用户 Posts 14 Credits 36 | |
|
Much more concise than I thought!
|
|
| Floor14 yayumyself | Posted 2007-06-21 18:21 |
| 初级用户 Posts 14 Credits 36 | |
|
@echo off&setlocal enabledelayedexpansion&color 1f
mode con:cols=50 lines=25 title Delete Unmatched Lyrics from MP3 http://hi.baidu.com/xinghuo set n=0 if "%~1"=="" ( echo Please directly drag and drop the folder containing music onto this file ping /n 6 127.0.0.1>nul&exit ) else ( echo Current detection directory is: %~1 ) echo _________ for %%i in ("%1\*.lrc") do ( if not exist %1\%%~ni.wma ( if not exist %1\%%~ni.mp3 set/a n+=1&set name!n!=%%i&echo %%~nxi --Not Find ) ) echo. if %n%==0 echo All lyrics are matched&echo Program from: http://hi.baidu.com/xinghuo&pause>nul&exit set /p sure=Do you want to delete these lyric files?(Y), press other keys to exit: if /i "%sure%"=="y" ( cls echo Deleting... for /l %%a in (1,1,%n%) do ( del "!name%%a!" 2>nul ) echo.&echo ^^_^^, The world is quiet! echo Program from: http://hi.baidu.com/xinghuo ) pause>nul exit |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |