![]() |
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-10-31 01:07 |
47,815 topics / 349,930 posts / today 0 new / 48,290 members |
| DOS批处理 & 脚本技术(批处理室) » A question about randomly obtaining file names. |
| Printable Version 19,446 / 54 |
| Floor16 zh159 | Posted 2006-07-27 20:38 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
|
I rewrote one, without text queries, using clearing the variables already written into the list to judge the loop-generated random numbers.
137 files completed within 30 seconds (if the random numbers are lucky then it will be faster; later on there are fewer valid variables so it gets slower): don't include the red parts
Seems there is a small problem: sometimes it exits with failure:( [ Last edited by zxcv on 2006-7-28 at 01:19 ] |
|
| Floor17 zh159 | Posted 2006-07-27 20:57 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
|
Here's one that automatically determines the file count and sets the random digit length:
@echo off |
|
| Floor18 voiL | Posted 2006-07-27 21:44 |
| 中级用户 Posts 189 Credits 384 | |
|
With so many people's code here, it should already be enough...
I'll take it all down and study it slowly, and hopefully piece together something faster and more efficient... ^_^ Thanks, everyone... |
|
| Floor19 无奈何 | Posted 2006-07-27 22:20 |
| 荣誉版主 Posts 356 Credits 1,338 | |
|
Re voiL
Here, the execution result is different every time, and there are no "numbers" before the filenames. Please post your results so I can take a look. |
|
| Floor20 zh159 | Posted 2006-07-27 22:42 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
|
Moderator 无奈何's is pretty good, and fast too
But filenames with spaces get cut off (incomplete); it should probably be possible to revise it a bit |
|
| Floor21 namejm | Posted 2006-07-27 23:00 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
Originally posted by doscc at 2006-7-27 20:38: I more or less figured out your filtering rule. There is a problem in your code in post #16. I don't know whether the red text is comments or code; if it's code, then after execution, list.txt will contain a large number of lines whose contents are “ clear the variable already written into the list”; if it's comments, then after removing the comment part, list.txt will contain a large number of lines whose contents are "ECHO is off." You said this code sometimes exits with failure. I guess it's because there are too many lines to process, leading to too many name!N! variables, and CMD seems to have a limit on the number of variables. [ Last edited by namejm on 2006-7-28 at 09:13 ] |
|
| Floor22 namejm | Posted 2006-07-27 23:09 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
Originally posted by zxcv at 2006-7-27 22:42: Other than the one place in post #9, where else is there an issue in Moderator 无奈何's code? I also want to take it and run it. |
|
| Floor23 doscc | Posted 2006-07-27 23:40 |
| 中级用户 Posts 93 Credits 256 From 广东 | |
Originally posted by namejm at 2006-7-27 23:00: The code in post #16 is by zxcv. Post #11 is my code. Updated now! |
|
| Floor24 无奈何 | Posted 2006-07-27 23:51 |
| 荣誉版主 Posts 356 Credits 1,338 | |
|
Re zxcv
Thanks for pointing it out. Filenames containing spaces really do have a problem. Here's a simple fix. Re namejm Please see the corrected code in this post.
|
|
| Floor25 zh159 | Posted 2006-07-28 00:00 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
|
Moderator 无奈何's code is very fast. With 137 files it took less than 3 seconds.
@echo off [ Last edited by zxcv on 2006-7-28 at 00:02 ] |
|
| Floor26 namejm | Posted 2006-07-28 00:50 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
Re doscc:
sorry, I misread your code. My bad. |
|
| Floor27 zh159 | Posted 2006-07-28 01:11 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
Originally posted by namejm at 2006-7-27 23:00: The text after that is comments, don't put it in the BAT I tested name!N! variables and even 548 was no problem. I guess it's echo set Name=%%Name!N!%%>Temp.bat call Temp.bat This part sometimes doesn't have time to respond [ Last edited by zxcv on 2006-7-28 at 01:18 ] |
|
| Floor28 namejm | Posted 2006-07-28 09:12 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
Re zxcv:
If your red text is comments, then that comment format is wrong, and in some places it can even cause execution errors. For example, the line set Name!N!=clear the variable already written into the list will assign the value "clear the variable already written into the list" to the variable Name!N!. I hope you can correct it. |
|
| Floor29 namejm | Posted 2006-07-28 09:25 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
Moderator 无奈何's code in post #25 is extremely concise, but also extremely puzzling. I stared at it for ages and still couldn't make heads or tails of it. Could it really be like what he once claimed before, that code should be written as concisely and as obscurely as possible? If it's just concise, that would be a blessing for people like us; but if you add “as obscure and hard to understand as possible,” good grief, I guess a whole batch of newbies like me will faint on the spot. I hope Moderator 无奈何 can give a little explanation of your code, so we can understand your train of thought. I don't feel satisfied with just the few words in post #9.
I found an interesting phenomenon: if you remove the opening line @echo off from the code in post #24, the contents of list.txt will increase greatly, with added content in the form of "\current folder name>echo 20454". Generally speaking, if there are N files, then this kind of content will also increase by N lines. Logically, the @echo off statement is only supposed to suppress echoing, but in this piece of code it actually affects the execution result, which is rather baffling. By the way, removing the @ in @echo %%b>>List.txt and @call :sub %%i in the code seems not to affect how the code behaves when executed. I don't know why Moderator 无奈何 still keeps the @. [ Last edited by namejm on 2006-7-28 at 10:59 ] |
|
| Floor30 zh159 | Posted 2006-07-28 09:42 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
Originally posted by namejm at 2006-7-28 09:12: Honestly, I added those when posting to explain what each line does. They were never in the real BAT to begin with (which is why I said: don't include the red parts); but you should be able to tell which parts are not supposed to be there, right? I don't really know how to add comments afterward without affecting the code ![]() |
|
| Prev 1 2 3 4 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |