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-20 15:55
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » A new method to randomly obtain file names View 3,008 Replies 5
Original Poster Posted 2006-12-09 13:46 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Four months ago, we discussed the method of randomly obtaining file names together and found that the best code is:
A question about randomly obtaining file names
The code from moderator Wunaihe on floor 24:

@echo off
if "%1" NEQ "$" (
for /f "tokens=1,2 delims=:" %%a in ('"%~0" $^|sort') do @echo %%b
) else for /f "delims=" %%i in ('dir /b /a-d *.mp3') do @call :sub %%i
goto :EOF

:sub
echo %random%:%*
goto :EOF

And the codes modified by everyone later

Tonight, inspired by the "set ." special usage (sorting) from redtek on floor 15 in:


@echo off
setlocal EnableDelayedExpansion
for /f "delims=" %%i in ('dir/a-d/b *.mp3') do set $!random!!random!$%%i=$
for /f "tokens=1,2* delims=$=" %%i in ('set $') do echo %%j
pause
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
ccwan +5 2006-12-09 21:43
Floor 2 Posted 2006-12-09 22:38 ·  中国 北京 东城区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
Brother, your code is concise and wonderful. I appreciate it.
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 3 Posted 2006-12-09 22:46 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Got up in the morning and thought of the application of call (without using delay variables ):
@echo off
for /f "delims=" %%i in ('dir/a-d/b *.mmf') do call set $%%random%%$%%i=$
for /f "tokens=1,2* delims=$=" %%i in ('set $') do echo %%j
pause
Floor 4 Posted 2006-12-09 22:50 ·  中国 北京 东城区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
Haha... This call was played beautifully~ :)
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 5 Posted 2006-12-10 00:45 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
19-year member
UID 62249
Status Offline
Strong, the code above can be slightly modified to scan for specified (type) files on the hard drive and perform related operations. For example, some time ago when the Viking virus was encountered, a batch file could be created and placed in the C drive:

@echo off
for /f "delims=" %%i in ('dir /a/b/s desktop.ini') do call set $%%random%%$%%i=$
for /f "tokens=1,2* delims=$=" %%i in ('set $') do echo %%j >>c:\deleted_virus_files.txt
pause

This will find all _desktop.ini files and perform the deletion operation.
Floor 6 Posted 2006-12-10 01:54 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
Originally posted by HUNRYBECKY at 2006-12-10 00:45:
Powerful, the code above can be slightly modified to scan for specified (type) files on the hard drive and perform related operations. For example, some time ago, the Viking virus was infected. You can create a batch file and place it in the C drive:
...


  The main file of the Viking virus is _desktop.ini, and if you do this, all desktop.ini files under the C drive will be deleted, which may affect some system properties.
Forum Jump: