|
XZ
初级用户
 
积分 144
发帖 65
注册 2008-3-20 来自 Taiwan
状态 离线
|
『楼 主』:
[求助]取得當前磁碟機代號與路徑
請問要如何取得當前執行的磁碟機代號呢?
我參考之前我詢問過的問題
http://www.cn-dos.net/forum/viewthread.php?tid=38824&fpage=1&highlight=
slore 在二樓提出的語法
修改後
@ECHO OFF
for /f "delims=" %%i in ('DIR') do SET DISKVOL=%%~Di
ECHO Now disk vol is %DISKVOL%
PAUSE 請問是否有更好的方法呢?
因為要是根目錄有一長串檔案可是會哭的 ^^"
補個問題
傳回當前路徑的話我就完全不會了^^
可否一起指教呢?
謝謝
[ Last edited by XZ on 2008-3-29 at 01:32 PM ]
|
|
2008-3-29 12:27 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
『第
2 楼』:
'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 ]
此帖被 +2 点积分 点击查看详情 评分人:【 XZ 】 | 分数: +2 | 时间:2008-3-29 13:29 |
|
|

简单!简单!再简单! |
|
2008-3-29 12:43 |
|
|
XZ
初级用户
 
积分 144
发帖 65
注册 2008-3-20 来自 Taiwan
状态 离线
|
『第
3 楼』:
Quote: | Originally posted by terse at 2008-3-29 12:43 PM:
'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 ] |
|
神人 ^^
語法縮短結果相同
要是在追加當前路徑呢?
可否可行!!
這個我就完全寫不出來了 ^^"
|
|
2008-3-29 13:31 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
『第
4 楼』:
SET DISKVOL=%~dp0
|

简单!简单!再简单! |
|
2008-3-29 13:37 |
|
|
XZ
初级用户
 
积分 144
发帖 65
注册 2008-3-20 来自 Taiwan
状态 离线
|
『第
5 楼』:
阿勒 原來是我甩白吃
看了剛剛 terse 的 %CD% 與 SET DISKVOL=%~D0 的提點
應該就要去查 SET 用法
查完才發現原來這麼簡單就可以查出當然目錄
@ECHO OFF
SET DISKVOL=%~D0
SET FLODERPAHT=%CD%
ECHO Now disk vol is %DISKVOL%
ECHO Now Path vol is %FLODERPAHT% 借問一下我稍微查了一下沒有發現 =%~D0 的用法耶
可否稍加解釋 謝謝您
|
|
2008-3-29 13:39 |
|
|
XZ
初级用户
 
积分 144
发帖 65
注册 2008-3-20 来自 Taiwan
状态 离线
|
『第
6 楼』:
剛用力找了一下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.
|
|
2008-3-29 13:44 |
|
|
abcd
银牌会员
    
积分 1436
发帖 739
注册 2007-10-11
状态 离线
|
『第
7 楼』:
何必到google去查呢,
微软系统自带就有的。
for /?
就可以查到的
|
|
2008-3-29 15:44 |
|
|
XZ
初级用户
 
积分 144
发帖 65
注册 2008-3-20 来自 Taiwan
状态 离线
|
『第
8 楼』:
Quote: | Originally posted by abcd at 2008-3-29 03:44 PM:
何必到google去查呢,
微软系统自带就有的。
for /?
就可以查到的 |
|
原來這兩個是一樣的喔
我一直以為 那個大寫的 I 和數字是不一樣的ˇˇ
如果要在批次程式中使用 FOR 命令,請指定 %%variable,而不要指定
%variable。 變數名稱有大小寫的區分,所以 %i 不同於 %I。 還是不懂 I 為什麼可以變成數字@@a
我在努力悟看看好了
|
|
2008-3-29 16:42 |
|