|
yishanju
银牌会员
     [b]看你妹啊[/b]
积分 1488
发帖 1357
注册 2006-5-20
状态 离线
|
『楼 主』:
怎么样用批处理运行一个目录里面最新的可执行文件?
使用 LLM 解释/回答一下
怎么样用批处理运行一个目录里面最新的可执行文件?
不考虑子目录,不用第三方工具,文件名没有规律,^_^看看大家都是怎么实现的
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
|
|
2007-3-13 03:30 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
放在要执行的文件所在的目录中运行,没有测试:
@echo off
for /f "delims=" %%a in ('dir /od/b *.exe') do set name="%%a"
%name%
Run it in the directory where the file to be executed is located, not tested:
@echo off
for /f "delims=" %%a in ('dir /od/b *.exe') do set name="%%a"
%name%
|
|
2007-3-13 03:36 |
|
|
yishanju
银牌会员
     [b]看你妹啊[/b]
积分 1488
发帖 1357
注册 2006-5-20
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
^_^
dir /o:d 才对吧或者 dir /o/d
^_^
dir /o:d is correct or dir /o/d
|
|
2007-3-13 03:42 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
Originally posted by yishanju at 2007-3-12 14:42:
^_^
dir /o:d 才对吧或者 dir /o/d
一样的效果,试试就知道了。
Originally posted by yishanju at 2007-3-12 14:42:
^_^
dir /o:d is correct, or dir /o/d
The effect is the same, just try it and you'll know.
|
|
2007-3-13 03:46 |
|
|
yishanju
银牌会员
     [b]看你妹啊[/b]
积分 1488
发帖 1357
注册 2006-5-20
状态 离线
|
|
2007-3-13 03:49 |
|
|
yishanju
银牌会员
     [b]看你妹啊[/b]
积分 1488
发帖 1357
注册 2006-5-20
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
^_^如果有文件名中有空格呢...会怎么样?
^_^What if there are spaces in the file name... What will happen?
|
|
2007-3-13 03:50 |
|
|
yishanju
银牌会员
     [b]看你妹啊[/b]
积分 1488
发帖 1357
注册 2006-5-20
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
D:\Documents and Settings\Administrator>%name%
'd' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
D:\Documents and Settings\Administrator>
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>
|
|
2007-3-13 03:53 |
|
|
yishanju
银牌会员
     [b]看你妹啊[/b]
积分 1488
发帖 1357
注册 2006-5-20
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
for /f "delims=" %%a in ('dir /od/b *.exe') do set name="%%a"
"%name%"
加上引号,如果文件名中有空格,应该也不会出错了吧
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
|
|
2007-3-13 03:55 |
|
|
yishanju
银牌会员
     [b]看你妹啊[/b]
积分 1488
发帖 1357
注册 2006-5-20
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
^_^ 想起一个问题,如果把这个批处理放到要运行的可执行程序的目录里边,那个这个批处就变成目录里最新的文件了
这样应该会造成死循环
^_^ 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.
|
|
2007-3-13 03:59 |
|
|
chainliq
高级用户
    学无尽止
积分 635
发帖 244
注册 2006-4-15 来自 广西贵港
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
for /f "delims=" %%a in ('dir /od/b *.exe') do set name="%%a"
%name%
path %name%
start %name%
这样可能也行,没试过哈```
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.
|

学无尽止 |
|
2007-3-13 04:01 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
Originally posted by yishanju at 2007-3-12 14:59:
^_^ 想起一个问题,如果把这个批处理放到要运行的可执行程序的目录里边,那个这个批处就变成目录里最新的文件了
这样应该会造成死循环
Re yishanju:
应该不会造成死循环,因为此批处理搜索的只是可执行文件(*.exe),而并非是批处理文件(*.bat、*.cmd),运行之后执行的也就不可能是批处理;
对于加上引号,是有必要的,防止可执行文件名含有空格导致运行可执行文件出错,是我疏忽了。
Originally posted by yishanju at 2007-3-12 14:59:
^_^ Remember a question, if you put this batch file into the directory of the executable program to be run, then this batch file becomes the latest file in the directory
This should cause an infinite loop
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.
|
|
2007-3-13 04:04 |
|
|
yishanju
银牌会员
     [b]看你妹啊[/b]
积分 1488
发帖 1357
注册 2006-5-20
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
应该不会造成死循环,因为此批处理搜索的只是可执行文件(*.exe),而并非是批处理文件(*.bat、*.cmd),运行之后执行的也就不可能是批处理;
^_^ 嗯,我想像的时候把.exe 去掉了
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
|
|
2007-3-13 04:10 |
|
|
yishanju
银牌会员
     [b]看你妹啊[/b]
积分 1488
发帖 1357
注册 2006-5-20
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
for /f "delims=" %%a in ('dir /od/b *.exe') do set name="%%a"
start "f:\tem%name%"
应该像这样加上start 才行.不然,底下的代码就有可能不执行了,
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.
|
|
2007-3-13 04:56 |
|
|
leton
初级用户
 
积分 170
发帖 72
注册 2007-3-11
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
楼主好像是要实现,智能判断目录最新可执行文件。
挺有意思,有空研究一下,前期思路:
通过把文件信息输出到 log.txt(信息收集)
然后导入 log.txt 进行判断(那个文件为最新执行文件)然后执行
不知道思路对不.
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.
|
|
2007-3-13 06:53 |
|
|
everest79
金牌会员
      一叶枝头,万树皆春
积分 2564
发帖 1127
注册 2006-12-25
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
dir /t:c /o:d 新建时间排序
dir /t:a /o:d 访问时间排序
dir /t:w /o:d 修改时间排序
lxmxn的好方法,原来都没注意过
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
|
|
2007-3-13 07:05 |
|