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-22 06:03
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » A question about randomly obtaining file names. DigestI View 17,411 Replies 54
Floor 46 Posted 2006-12-11 07:49 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
Repeated sort still only goes by the last one. If you sort once and extract once, that would undoubtedly be putting the cart before the horse.
If the requirements aren't high, you can stop at a superficial taste; otherwise, it's still better to use random.
Floor 47 Posted 2006-12-20 23:36 ·  中国 湖南 娄底 电信
初级用户
Credits 28
Posts 11
Joined 2006-11-05 21:22
19-year member
UID 69699
Gender Male
Status Offline
Please see whether this works
@echo off
for %%i in (*.mp3) do (
echo %%i >>1.txt
)
exit
Floor 48 Posted 2007-01-21 01:33 ·  中国 广东 阳江 电信
新手上路
Credits 8
Posts 4
Joined 2007-01-15 12:34
19-year member
UID 76585
Gender Male
Status Offline
Saved it, will study it later
Floor 49 Posted 2007-02-01 02:58 ·  中国 湖南 长沙 联通
社区乞丐
★★
gaoshou
Credits -16
Posts 77
Joined 2007-01-30 09:11
19-year member
UID 78105
Gender Male
Status Offline
Bump again
This really is great
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
look +1 2007-10-22 13:59
:cool:
Floor 50 Posted 2007-03-02 02:28 ·  中国 山东 青岛 联通
新手上路
Credits 10
Posts 5
Joined 2006-11-21 04:48
19-year member
UID 71206
Gender Male
Status Offline
To achieve WMP random playback.
Doesn't the player already have that function?
So much changing back and forth is such a hassle
Floor 51 Posted 2007-03-09 02:28 ·  新西兰
初级用户
Credits 107
Posts 47
Joined 2007-03-03 03:12
19-year member
UID 80618
Gender Male
Status Offline
All experts, I’m convinced by you guys
Floor 52 Posted 2007-03-09 10:15 ·  中国 湖北 武汉 电信
初级用户
Credits 22
Posts 10
Joined 2007-02-16 22:46
19-year member
UID 79647
Gender Male
Status Offline
@echo off
setlocal ENABLEDELAYEDEXPANSION

set /p mypath=Enter the directory where the MP3 files are located; press Enter directly to use the current directory:
set t1=%time%
set /a num=1
rem The line below can't handle paths with spaces (can anyone tell me how to solve this?)
rem for /f %%i in ('dir /b *.mp3') do (
rem The line below can handle spaces, please modify the path yourself
for /R %mypath% %%i in (*.mp3) do (
set s!num!=%%i
set /a num+=1
)

set /a fcount=%num%
set /a fcount-=1

:loop
set /a rnd=%random%
set /a rnd%%=%num%
set /a rnd+=1

if not "!s%rnd%!"=="" (
echo !s%rnd%!
call :swap %rnd% "!s%num%!"
set s%num%=
set /a num-=1
)

if %num% GTR 1 goto loop

echo Total files:%fcount%
echo Start time:%t1%
echo End time:%time%

:swap
set stmp=%2
set s%1=%stmp:~1,-1%

[ Last edited by test266 on 2007-3-9 at 11:29 AM ]
Floor 53 Posted 2007-03-09 22:47 ·  中国 辽宁 本溪 联通
银牌会员
★★★
Credits 1,212
Posts 464
Joined 2006-12-13 21:11
19-year member
UID 73417
Gender Male
Status Offline
Looks like the poster below can't handle filenames with spaces and hyphens...
Floor 54 Posted 2008-12-30 23:27 ·  中国 贵州 安顺 电信
初级用户
Credits 94
Posts 49
Joined 2008-12-14 20:47
17-year member
UID 133884
Gender Male
Status Offline
Originally posted by zh159 at 2006-12-10 14:29:
Add my latest one to this thread too ^_^

@echo off
for /f "delims=" %%i in ('dir/a-d/b *.mp3') do call set $%%random%%$%%i=$
for /f "tokens=1,2* delims=$=" %%i in ('set $ ...

This is pretty nice if you change it for listening to music, random playback from an empty playlist.
@echo off
for /f "delims=" %%i in ('dir/a-d/b/s *.mp3,*.wma,*.ape') do call set $%%random%%$%%i=$
for /f "tokens=1,2* delims=$=" %%i in ('set $') do "C:\Program Files\MPlayer\mplayer.exe" "%%j"

I feel the one below is a bit faster.
@echo off
for /r . %%i in (*.mp3,*.wma,*.ape) do call set $%%random%%$%%i=$
for /f "tokens=1,2* delims=$=" %%i in ('set $') do "C:\Program Files\MPlayer\mplayer.exe" "%%j"


[ Last edited by linee on 2008-12-31 at 05:28 ]
Floor 55 Posted 2009-01-05 15:07 ·  中国 贵州 安顺 电信
初级用户
Credits 94
Posts 49
Joined 2008-12-14 20:47
17-year member
UID 133884
Gender Male
Status Offline
Referring to post #24 and post #34, I'll post my modified one here too.
@echo off
(for %1 %%i in (*.mp3,*.wma)do call echo %%random%%=%%i)%3>nul&%2:EOF
for /f "tokens=2delims==" %%a in ('"%~0" /r,goto,2^|sort')do echo %%a

Or
@echo off&%~1
for /f "tokens=2delims==" %%a in ('%~0 "(for /r %%i in (*.mp3,*.wma)do call echo %%^random%%=%%i)&goto:EOF"^|sort')do echo %%a


[ Last edited by linee on 2009-1-7 at 23:09 ]
Forum Jump: