![]() |
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-09-15 12:31 |
47,812 topics / 349,917 posts / today 0 new / 48,268 members |
| DOS批处理 & 脚本技术(批处理室) » How to run the latest executable file in a directory using batch processing? |
| Printable Version 3,365 / 17 |
| Floor1 yishanju | Posted 2007-03-13 03:30 |
| 银牌会员 Posts 1,357 Credits 1,488 | |
|
How to use batch processing to run the latest executable file in a directory? Ignoring subdirectories, without using third-party tools, and the file names have no pattern, ^_^ Let's see how everyone implements it
|
|
| Floor2 lxmxn | Posted 2007-03-13 03:36 |
| 版主 Posts 4,938 Credits 11,386 | |
|
Run it in the directory where the file to be executed is located, not tested:
|
|
| Floor3 yishanju | Posted 2007-03-13 03:42 |
| 银牌会员 Posts 1,357 Credits 1,488 | |
|
^_^
dir /o:d is correct or dir /o/d |
|
| Floor4 lxmxn | Posted 2007-03-13 03:46 |
| 版主 Posts 4,938 Credits 11,386 | |
Originally posted by yishanju at 2007-3-12 14:42: The effect is the same, just try it and you'll know. |
|
| Floor5 yishanju | Posted 2007-03-13 03:49 |
| 银牌会员 Posts 1,357 Credits 1,488 | |
| Floor6 yishanju | Posted 2007-03-13 03:50 |
| 银牌会员 Posts 1,357 Credits 1,488 | |
|
^_^What if there are spaces in the file name... What will happen?
|
|
| Floor7 yishanju | Posted 2007-03-13 03:53 |
| 银牌会员 Posts 1,357 Credits 1,488 | |
|
D:\Documents and Settings\Administrator>%name%
'd' is not an internal or external command, nor is it a runnable program or batch file. D:\Documents and Settings\Administrator> |
|
| Floor8 yishanju | Posted 2007-03-13 03:55 |
| 银牌会员 Posts 1,357 Credits 1,488 | |
|
for /f "delims=" %%a in ('dir /od/b *.exe') do set name="%%a"
"%name%" Adding quotes, if there are spaces in the file name, it shouldn't go wrong, right |
|
| Floor9 yishanju | Posted 2007-03-13 03:59 |
| 银牌会员 Posts 1,357 Credits 1,488 | |
|
^_^ Think of a problem. If you put this batch file into the directory of the executable program to be run, then this batch file will become the latest file in the directory. This should cause an infinite loop.
|
|
| Floor10 chainliq | Posted 2007-03-13 04:01 |
| 高级用户 Posts 244 Credits 635 From 广西贵港 | |
|
for /f "delims=" %%a in ('dir /od/b *.exe') do set name="%%a"
%name% path %name% start %name% This might also work, but I haven't tried it. |
|
| Floor11 lxmxn | Posted 2007-03-13 04:04 |
| 版主 Posts 4,938 Credits 11,386 | |
Originally posted by yishanju at 2007-3-12 14:59: Re yishanju: It should not cause an infinite loop because this batch file searches only for executable files (*.exe), not batch files (*.bat, *.cmd), so what is executed after running cannot be the batch file; Adding quotes is necessary to prevent errors when running the executable file due to spaces in the executable file name. I overlooked this. |
|
| Floor12 yishanju | Posted 2007-03-13 04:10 |
| 银牌会员 Posts 1,357 Credits 1,488 | |
|
It should not cause an infinite loop because this batch processing only searches for executable files (*.exe), not batch files (*.bat, *.cmd), so what is executed after running cannot be a batch process; ^_^ Well, I removed the .exe when I was thinking about it
|
|
| Floor13 yishanju | Posted 2007-03-13 04:56 |
| 银牌会员 Posts 1,357 Credits 1,488 | |
|
for /f "delims=" %%a in ('dir /od/b *.exe') do set name="%%a"
start "f:\tem%name%" It should be added with start like this. Otherwise, the code below may not execute. |
|
| Floor14 leton | Posted 2007-03-13 06:53 |
| 初级用户 Posts 72 Credits 170 | |
|
The LZ seems to be going to implement intelligent judgment of the latest executable file in the directory.
It's quite interesting. I'll study it when I have time. The early ideas: Output file information to log.txt (information collection) Then import log.txt for judgment (which file is the latest executable file) and then execute I don't know if the idea is correct. |
|
| Floor15 everest79 | Posted 2007-03-13 07:05 |
| 金牌会员 Posts 1,127 Credits 2,564 | |
|
dir /t:c /o:d Sort by creation time
dir /t:a /o:d Sort by access time dir /t:w /o:d Sort by modification time Good method of lxmxn, I didn't notice it before |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |