China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-12 04:01
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Problems with %~fsi in the for statement??? View 1,575 Replies 8
Original Poster Posted 2006-11-29 06:20 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 141
Posts 60
Joined 2006-10-28 05:54
19-year member
UID 68605
Gender Male
From 天津
Status Offline
I looked up for /?
%~fsI is to expand %I to the full path name containing only the short name.
Through experimentation
SET WL_HOME=C:\bea\weblogic91
FOR %%i IN ("%WL_HOME%") DO SET WL_HOME=%%~fsi
echo %WL_HOME%
pause
It shows WL_HOME=C:\bea\WEBLOG~1
I don't know how to explain the sentence "expand %I to the full path name containing only the short name"
Let's explain: In Windows, for a long file or directory name, there is a corresponding short name. For example, "weblogic91" has a short name "WEBLOG~1". When using %~fsI in a for loop, it takes the variable %I (here it's "%WL_HOME%") and expands it to the full path but using the short name part. So in the example, %WL_HOME% is "C:\bea\weblogic91", and when processed with %%~fsi, it becomes the full path with the short name part, so it's "C:\bea\WEBLOG~1".
Floor 2 Posted 2006-11-29 06:59 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline

You can understand it this way. If %i refers to a file, then %~fsi refers to the path and short filename of this file. This process is called expansion.
Floor 3 Posted 2006-11-29 23:00 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 141
Posts 60
Joined 2006-10-28 05:54
19-year member
UID 68605
Gender Male
From 天津
Status Offline
What is the definition of the so-called short filename? C:\bea\weblogic91 How does it become C:\bea\WEBLOG~1?
Floor 4 Posted 2006-11-30 01:17 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
What I "Baidu" for you:

When there are long file names on a disk or directory, since DOS can only recognize "8.3 format" files, it will take the first "6 letters" of the long file name plus "~1" to represent it. For example, "C:\Program Files" should be written as "C:\Progra~1". If there is another file named "Program Common", then the names will be like this: 

"C:\Program Common" should be written as "C:\Progra~1",
"C:\Program Files" should be written as "C:\Progra~2",

That is to say, it is written in alphabetical order.
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 5 Posted 2006-11-30 01:23 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
Here's the translation:

Here's an example:

@echo off
for %%i in (.) do @echo %%~si
pause>nul

The above code is saved as a *.bat file. When run in any directory, you can see the short name of the current directory.
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 6 Posted 2006-11-30 02:28 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 141
Posts 60
Joined 2006-10-28 05:54
19-year member
UID 68605
Gender Male
From 天津
Status Offline
Thanks ccwan
Got it
Floor 7 Posted 2007-01-13 03:53 ·  中国 广东 湛江 电信
初级用户
Credits 22
Posts 10
Joined 2007-01-12 09:58
19-year member
UID 76274
Gender Male
Status Offline
Please clarify the specific context of these symbols in the batch processing you mentioned. Different symbols may have different specific uses in batch commands. For example, the caret (^) is often used as an escape character, the exclamation mark (!) may be related to delayed expansion in certain scenarios, the minus sign (-) may be used in range expressions, and the tilde (~) may have specific meanings in parameter substitution, etc. But without more detailed context, it's difficult to give an extremely accurate and detailed explanation.
Floor 8 Posted 2007-01-13 03:56 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Originally posted by xuzhenhui at 2007-1-12 14:53:
May I ask you all about the functions and usages of special symbols such as "^ ! -1 ~" in batch processing


  DOS Symbol Issues

  Go to the 4th floor of the above post to have a look, which will be helpful to you.


[ Last edited by lxmxn on 2007-1-12 at 02:57 PM ]
Floor 9 Posted 2009-06-18 22:43 ·  中国 北京 联通
初级用户
Credits 25
Posts 20
Joined 2009-06-16 23:10
17-year member
UID 147569
Status Offline
Forum Jump: