中国DOS联盟论坛

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-11 07:04
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » Sort the MP3 playback order, which can handle long files and file names with spaces
Printable Version  2,334 / 10
Floor1 thisiscx Posted 2007-11-14 12:06
新手上路 Posts 6 Credits 11
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...............................................................................
Floor2 lxmxn Posted 2007-11-14 16:14
版主 Posts 4,938 Credits 11,386
This command can get it done:
Floor3 zh159 Posted 2007-11-15 09:20
金牌会员 Posts 1,467 Credits 3,687
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"
Floor4 thisiscx Posted 2007-11-15 16:26
新手上路 Posts 6 Credits 11
Thanks to moderator lxmxn and大侠 zh159.
Floor5 thisiscx Posted 2007-11-15 16:43
新手上路 Posts 6 Credits 11
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?
Floor6 lxmxn Posted 2007-11-15 18:06
版主 Posts 4,938 Credits 11,386
It should not have this problem. Did you write it in the form of "D:\music"?
Floor7 thisiscx Posted 2007-11-16 12:20
新手上路 Posts 6 Credits 11
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?
Floor8 lxmxn Posted 2007-11-16 12:41
版主 Posts 4,938 Credits 11,386
Of course there is a problem.
If you remove it, it will be like this:
Floor9 thisiscx Posted 2007-11-19 10:27
新手上路 Posts 6 Credits 11
Got it, thank you, moderator lxmxn
Floor10 thisiscx Posted 2009-02-02 17:30
新手上路 Posts 6 Credits 11
Excuse me, how to use the copy command to copy files in random order?
Floor11 523066680 Posted 2009-02-02 18:27
银牌会员 Posts 1,133 Credits 2,362
(Let me interject) Have to be surprised... The above is a super-long conversation between 2007 and 2009...
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023