![]() |
中国DOS联盟-- 联合DOS 推动DOS 发展DOS --联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum |
| 游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟 |
|
中国DOS联盟论坛 现在时间是 2026-08-07 22:41 |
共 48,041 主题排行 / 350,128 发帖 / 今日 3 篇 / 48,252 会员排行 |
| DOS批处理 & 脚本技术(批处理室) » [求助]取得當前磁碟機代號與路徑 |
| 可打印版本 867 / 7 |
| 第1楼 XZ | 发表于 2008-03-29 12:27 |
| 初级用户 发帖 65 积分 144 来自 Taiwan | |
|
[求助]取得當前磁碟機代號與路徑 請問要如何取得當前執行的磁碟機代號呢?
我參考之前我詢問過的問題 http://www.cn-dos.net/forum/viewthread.php?tid=38824&fpage=1&highlight= slore 在二樓提出的語法 修改後 請問是否有更好的方法呢? 因為要是根目錄有一長串檔案可是會哭的 ^^" 補個問題 傳回當前路徑的話我就完全不會了^^ 可否一起指教呢? 謝謝 [ Last edited by XZ on 2008-3-29 at 01:32 PM ] |
|
| 第2楼 terse | 发表于 2008-03-29 12:43 |
| 银牌会员 发帖 946 积分 2,404 | |
|
'DIR'换成"%CD%"?
是不是这样? @ECHO OFF SET DISKVOL=%~D0 ECHO Now disk vol is %DISKVOL% PAUSE [ Last edited by terse on 2008-3-29 at 12:45 PM ] |
|
| 第3楼 XZ | 发表于 2008-03-29 13:31 |
| 初级用户 发帖 65 积分 144 来自 Taiwan | |
Originally posted by terse at 2008-3-29 12:43 PM: 神人 ^^ 語法縮短結果相同 要是在追加當前路徑呢? 可否可行!! 這個我就完全寫不出來了 ^^" |
|
| 第4楼 terse | 发表于 2008-03-29 13:37 |
| 银牌会员 发帖 946 积分 2,404 | |
|
SET DISKVOL=%~dp0
|
|
| 第5楼 XZ | 发表于 2008-03-29 13:39 |
| 初级用户 发帖 65 积分 144 来自 Taiwan | |
|
阿勒 原來是我甩白吃
看了剛剛 terse 的 %CD% 與 SET DISKVOL=%~D0 的提點 應該就要去查 SET 用法 查完才發現原來這麼簡單就可以查出當然目錄 借問一下我稍微查了一下沒有發現 =%~D0 的用法耶 可否稍加解釋 謝謝您 |
|
| 第6楼 XZ | 发表于 2008-03-29 13:44 |
| 初级用户 发帖 65 积分 144 来自 Taiwan | |
|
剛用力找了一下GOOGLE
有查到一些資料有需要的大家參考看看 BTW: 0 與 1的差別在哪? ^^" The following table lists the modifiers you can use in expansion. Modifier Description %~1 Expands %1 and removes any surrounding quotation marks (""). %~f1 Expands %1 to a fully qualified path name. %~d1 Expands %1 to a drive letter. %~p1 Expands %1 to a path. %~n1 Expands %1 to a file name. %~x1 Expands %1 to a file extension. %~s1 Expanded path contains short names only. %~a1 Expands %1 to file attributes. %~t1 Expands %1 to date and time of file. %~z1 Expands %1 to size of file. %~$PATH:1 Searches the directories listed in the PATH environment variable and expands %1 to the fully qualified name of the first one found. If the environment variable name is not defined or the file is not found, this modifier expands to the empty string. The following table lists possible combinations of modifiers and qualifiers that you can use to get compound results. Modifier Description %~dp1 Expands %1 to a drive letter and path. %~nx1 Expands %1 to a file name and extension. %~dp$PATH:1 Searches the directories listed in the PATH environment variable for %1 and expands to the drive letter and path of the first one found. %~ftza1 Expands %1 to a dir-like output line. Note In the previous examples, you can replace %1 and PATH with other batch parameter values. The %* modifier is a unique modifier that represents all arguments passed in a batch file. You cannot use this modifier in combination with the %~ modifier. The %~ syntax must be terminated by a valid argument value. You cannot manipulate batch parameters in the same manner that you can manipulate environment variables. You cannot search and replace values or examine substrings. However, you can assign the parameter to an environment variable, and then manipulate the environment variable. |
|
| 第7楼 abcd | 发表于 2008-03-29 15:44 |
| 银牌会员 发帖 739 积分 1,436 | |
|
何必到google去查呢,
微软系统自带就有的。 for /? 就可以查到的 |
|
| 第8楼 XZ | 发表于 2008-03-29 16:42 |
| 初级用户 发帖 65 积分 144 来自 Taiwan | |
Originally posted by abcd at 2008-3-29 03:44 PM: 原來這兩個是一樣的喔 我一直以為 那個大寫的 I 和數字是不一樣的ˇˇ 還是不懂 I 為什麼可以變成數字@@a 我在努力悟看看好了 |
|
|
[ 联系联盟系统管理团队 -
中国DOS联盟 -
标准版 ] Sponsored by ifanr Inc | © 2001–2023 |