China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-25 06:55
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Let's help use batch processing to find MP3s without accompanying lyrics. View 3,086 Replies 13
Original Poster Posted 2006-10-01 21:17 ·  中国 江西 吉安 遂川县 电信
中级用户
★★
Credits 253
Posts 112
Joined 2006-05-31 11:12
20-year member
UID 56308
Gender Male
Status Offline
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 ]
Floor 2 Posted 2006-10-01 21:45 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
@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 ]
Floor 3 Posted 2006-10-01 22:03 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
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:


@echo off
del /a /f /q G:\list.txt 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
start G:\list.txt


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 ]
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 4 Posted 2006-10-01 22:35 ·  中国 江西 吉安 遂川县 电信
中级用户
★★
Credits 253
Posts 112
Joined 2006-05-31 11:12
20-year member
UID 56308
Gender Male
Status Offline
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?
Floor 5 Posted 2006-10-01 23:03 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
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):

@echo off
setlocal enabledelayedexpansion
del /a /f /q G:\list.txt 2>nul
for /r %%i in (.) do (
set route=%%i
set route=!route:~0,-2!
echo -------!route!>>G:\list.txt
for %%j in ("%%i\*.mp3" "%%i\*.wma") do (
if not exist %%~nj.lrc echo %%~nj>>G:\list.txt
)
)
start notepad G:\list.txt
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 6 Posted 2006-10-01 23:30 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
All folders in the current directory are okay.
Note: Folders should not have spaces or sensitive characters.

@echo on
cd.>list.txt
setlocal enabledelayedexpansion
for /f %%i in ('dir/ad/b/s') do (
set D=%%i
call :List !D:%cd%\=!)
exit

:List
for %%i in ("%1\*.mp3" "%1\*.wma") do if not exist "%1\%%~ni.lrc" >>list.txt echo %1\%%~ni
goto :eof


If you want to distinguish between MP3 format and WMA format, change it to ">>list.txt echo %1\%%i"
Floor 7 Posted 2006-10-01 23:54 ·  中国 江苏 苏州 电信
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
```
@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 ]
Floor 8 Posted 2006-10-02 00:21 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
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.


@echo off
set route=%cd%
if exist list.txt del /a list.txt
setlocal enabledelayedexpansion
for /r %%m in (.) do (
set list=%%m
set list=!list:~0,-2!
cd /d !list!
set num=
for /f "tokens=*" %%i in ('dir /a-d /b *.mp3 *.wma') do (
if "!num!"==" " echo ===!list!===>>"%route%\list.txt" & set num=
if not exist %%~ni.lrc echo %%i>>"%route%\list.txt"
)
)
start "" "%route%\list.txt"


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 ]
Floor 9 Posted 2006-10-02 02:09 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
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!


@echo off
set route=%cd%
set term=
set take=set list=%%~dpi
if exist file.txt del /a file.txt
setlocal enabledelayedexpansion
for /f "tokens=*" %%i in ('dir /s /a-d /b *.mp3 *.wma') do (
!take!
if "!list!"=="%%~dpi" (
set take=
) else (
set term= & set take=set list=%%~dpi
)
if "!term!"==" " echo ===%%~dpi===>>"%route%\file.txt" & set term=
if not exist %%~dpni.lrc echo %%~nxi>>"%route%\file.txt"
)
start "" "%route%\file.txt"



[ Last edited by pengfei on 2006-10-2 at 05:34 ]
Floor 10 Posted 2006-10-02 05:18 ·  中国 北京 中移铁通
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
20-year member
UID 40733
Gender Male
Status Offline
Simple command-line display version:

@for /r %i in (*.mp3 *.wma) do @if not exist "%~ni.lrc" echo. %%i


Strictly formatted version:

@del /a /f /q G:\list.txt 2>nul
@for /r %%i in (*.mp3 *.wma) do @if not exist "%%~dpni.lrc" call :sub "%%i"
@goto :EOF
:sub
@if "%~dp1" NEQ "%dir%" set "dir=%~dp1" &echo. ---%dir%>>G:\list.txt
@if not exist "%~dpn1.lrc" echo. %~n1>>G:\list.txt
@goto :EOF
  ☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul

Floor 11 Posted 2006-10-02 08:27 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
:sub
@if "%~dp1" NEQ "%dir%" set "dir=%~dp1" &echo. ---%dir%>>G:\list.txt
@if not exist "%~dpn1.lrc" echo. %~n1>>G:\list.txt
@goto :EOF

Found that %%i is reassigned to %1, and it can still use the variable expansion of for.....
Floor 12 Posted 2006-10-03 08:01 ·  中国 四川 阿坝藏族羌族自治州 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
It would be nice if we could get something like Qianqian Jingting that automatically downloads lyrics.
Floor 13 Posted 2007-06-21 17:35 ·  中国 山西 太原 联通
初级用户
Credits 36
Posts 14
Joined 2006-09-06 20:48
19-year member
UID 61977
Gender Male
Status Offline
Much more concise than I thought!
Floor 14 Posted 2007-06-21 18:21 ·  中国 山西 太原 联通
初级用户
Credits 36
Posts 14
Joined 2006-09-06 20:48
19-year member
UID 61977
Gender Male
Status Offline
@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
Forum Jump: