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-08-11 07:58
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Sort the MP3 playback order, which can handle long files and file names with spaces View 2,336 Replies 10
Original Poster Posted 2007-11-14 12:06 ·  中国 陕西 咸阳 电信
新手上路
Credits 11
Posts 6
Joined 2007-11-09 10:18
18-year member
UID 102123
Gender Male
Status Offline
I wrote a DOS batch script to sort the playback order of MP3s. Please correct it.
Usually, the playback order is the same as the copying order. Therefore, controlling the copying order of song files to a USB flash drive or MP3 player can produce the effect of playing in the specified order. The order can be the reverse order of modification time, file size, file name, or extension. The sorting method is specified in the /O parameter of dir. /O-d will give priority to copying the files with the latest modification time. For more sorting methods, refer to the content of /O in dir /?.
In this sample batch script, the default drive letter of the USB flash drive (or MP3 player) is J:. There is a d:\music folder on D:, and the song files are in d:\music. The content of the sample batch script lcopy.bat is:

rem Batch file name: lcopy.bat
rem Function: Copy files in the specified order. The order can be the reverse order of modification time, file size, file name, or extension
rem The sorting method is specified in the /O parameter of dir. /O-d will give priority to copying the files with the latest modification time
rem Typical application: Copy MP3 files to the USB flash drive in the specified order. Usually, the copying order is the playback order
rem Parameter: The default drive letter of the USB flash drive is J:. There is a d:\music folder on D:, and the MP3 files are in d:\music
@echo Copy MP3 files to the USB flash drive in the specified order.............................................
d:
cd\music
if exist (lcopy.txt) del lcopy.txt
dir /o-d /b >lcopy.txt
FOR /F "delims=;" %%i in (lcopy.txt) do copy /y "%%i" j:\music
del lcopy.txt
@echo Copy completed...............................................................................
Floor 2 Posted 2007-11-14 16:14 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
This command can get it done:
for /f "delims=" %%a in ('dir /o-d/s/b/a-d D:\music') do copy "%%a" J:\music
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
thisiscx +1 2007-11-15 16:44
Floor 3 Posted 2007-11-15 09:20 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
21-year member
UID 44210
Status Offline
The places that need to be modified:

Since using ">lcopy.txt", there is no need to use "if exist (lcopy.txt) del lcopy.txt". If you simply use "dir /o-d /b >lcopy.txt" to generate the list, the newly generated "lcopy.txt" will also be included. Change it to "dir /o-d /b *.mp3>lcopy.txt"
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
thisiscx +1 2007-11-15 16:44
Floor 4 Posted 2007-11-15 16:26 ·  中国 陕西 咸阳 电信
新手上路
Credits 11
Posts 6
Joined 2007-11-09 10:18
18-year member
UID 102123
Gender Male
Status Offline
Thanks to moderator lxmxn and大侠 zh159.
Floor 5 Posted 2007-11-15 16:43 ·  中国 陕西 咸阳 电信
新手上路
Credits 11
Posts 6
Joined 2007-11-09 10:18
18-year member
UID 102123
Gender Male
Status Offline
May I ask, when executing according to the statements of moderator lxmxn, it prompts that the file is not found. Because when actually executing, there is only the file name in the "", without the path name. How should I deal with this?
Floor 6 Posted 2007-11-15 18:06 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
It should not have this problem. Did you write it in the form of "D:\music"?
Floor 7 Posted 2007-11-16 12:20 ·  中国 陕西 咸阳 电信
新手上路
Credits 11
Posts 6
Joined 2007-11-09 10:18
18-year member
UID 102123
Gender Male
Status Offline
Originally posted by lxmxn at 2007-11-15 18:06:
This problem should not occur. Did you write it in the form of "D:\music"?


I copied your statement, removed /s/a-d, and used it directly. Is there a problem?
Floor 8 Posted 2007-11-16 12:41 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Of course there is a problem.
If you remove it, it will be like this:
for /f "delims=" %%a in ('dir /o-d/b D:\music') do copy "D:\music\%%a" J:\music
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
thisiscx +1 2007-11-19 10:28
Floor 9 Posted 2007-11-19 10:27 ·  中国 陕西 咸阳 电信
新手上路
Credits 11
Posts 6
Joined 2007-11-09 10:18
18-year member
UID 102123
Gender Male
Status Offline
Got it, thank you, moderator lxmxn
Floor 10 Posted 2009-02-02 17:30 ·  中国 陕西 咸阳 电信
新手上路
Credits 11
Posts 6
Joined 2007-11-09 10:18
18-year member
UID 102123
Gender Male
Status Offline
Excuse me, how to use the copy command to copy files in random order?
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
HAT -2 2009-02-03 05:38
Floor 11 Posted 2009-02-02 18:27 ·  中国 广东 广州 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
(Let me interject) Have to be surprised... The above is a super-long conversation between 2007 and 2009...
Forum Jump: