中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --
联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟
中国DOS联盟论坛
现在时间是 2026-08-07 16:18
48,041 主题排行 / 350,128 发帖 / 今日 3 篇 / 48,252 会员排行
DOS批处理 & 脚本技术(批处理室) » [求助]文件拖动到批处理后的参数问题
可打印版本  828 / 5
第1楼 h2thesun 发表于 2008-03-03 13:44
初级用户 发帖 14 积分 34
[求助]文件拖动到批处理后的参数问题
if exist autorun.inf goto exist
echo.>autorun.inf
:exist
echo [autorun]>> autorun.inf
echo icon=%1>> autorun.inf
pause
以上是一个制作U盘图标的代码,如果直接运行可以生成autorun.inf的文件,但是如果拖动一个图标文件到该批处理时就不能生成autorun.inf文件,而且发现运行的代码也比较奇怪。高手请教一下。
第2楼 HAT 发表于 2008-03-03 15:10
版主 发帖 5,017 积分 9,023
重定向出问题了

if exist autorun.inf goto exist
>autorun.inf echo.
:exist
>>autorun.inf echo [autorun]
>>autorun.inf echo icon=%1
pause
第3楼 h2thesun 发表于 2008-03-03 16:18
初级用户 发帖 14 积分 34
Originally posted by HAT at 2008-3-3 03:10 PM:
重定向出问题了

if exist autorun.inf goto exist
>autorun.inf echo.
:exist
>>autorun.inf echo
>>autorun.inf echo icon=%1
pause

还是不行啊。文件拖上去还是不运行。
第4楼 mkd 发表于 2008-03-03 21:10
初级用户 发帖 30 积分 109
在最前面加上一行
cd /d "%~dp1"


如果 %1 沒有空格,不可以有 =
第5楼 h2thesun 发表于 2008-03-03 23:24
初级用户 发帖 14 积分 34
我自己发现如果重定向的文件是有具体路径的话(例子里就是可以把原来的autorun.inf改成l:\autorun.inf等等)就不会出问题。
现在又细看了一下mkd兄的方法,原因找到了,原来在其它文件拖到批处理文件上运行的时候,cmd中的运行目录是在C:\Documents and Settings\Administrator的默认目录下运行的,而不指定绝对路径的autorun.inf也是生成在C:\Documents and Settings\Administrator下的(后来去检查了一下,果然有一个autorun.inf在)。
但是mkd的这句不懂啊:”如果 %1 沒有空格,不可以有 =“ 是什么意思呢?
第6楼 mkd 发表于 2008-03-04 23:08
初级用户 发帖 30 积分 109
aa.bat


將x,y.txt x;y.txt x=y.txt 拖到aa.bat


cmd /c ""C:\aa.bat" C:\x,y.txt C:\x;y.txt C:\x=y.txt"
C:\x
y.txt
C:\x
y.txt
C:\x
y.txt
END



將x ,y.txt x ;y.txt x =y.txt 拖到aa.bat

cmd /c ""C:\aa.bat" "C:\x ,y.txt" "C:\x ;y.txt" "C:\x =y.txt""
"C:\x ,y.txt"
"C:\x ;y.txt"
"C:\x =y.txt"



END



將C:\A B\x,y.txt C:\A B\x;y.txt C:\A B\x=y.txt 拖到C:\A B\aa.bat

cmd /c ""C:\A B\aa.bat" "C:\A B\x,y.txt" "C:\A B\x;y.txt" "C:\A B\x=y.txt""
"C:\A B\x,y.txt"
"C:\A B\x;y.txt"
"C:\A B\x=y.txt"



END



http://www.cn-dos.net/forum/viewthread.php?tid=31223
[ 联系联盟系统管理团队 - 中国DOS联盟 - 标准版 ]
Sponsored by ifanr Inc | © 2001–2023