[求助]请问P处能不能得到一个文件名的短文件名
🖨 打印本页
标题:[求助]请问P处能不能得到一个文件名的短文件名
作者:ttj36 | 时间:2008-08-10 18:20 | 标题:[求助]请问P处能不能得到一个文件名的短文件名
哪个高手知道不,
高手们,我都看不懂了,我打个比方,
我要得到D盘下一个文件的短文件名,要在CMD里显示出它的短文件名字,
谢谢在面几位。顺便问一下
xx..\这种件夹的短名怎么得到,用下面的方法不行哦
[ Last edited by ttj36 on 2008-8-11 at 02:49 PM ]
作者:terse | 时间:2008-08-10 18:30
for %%i in (*) do echo %%~snxi
作者:ttj36 | 时间:2008-08-10 18:43
我怎么用不来,请问如何使用,
作者:pusofalse | 时间:2008-08-10 18:54
%~sI - expanded path contains short names only
The modifiers can be combined to get compound results:
%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~dp$PATH:I - searches the directories listed in the PATH
environment variable for %I and expands to the
drive letter and path of the first one found.
%~ftzaI - expands %I to a DIR like output line
作者:HAT | 时间:2008-08-11 01:49
@echo off
for %%i in ("C:\test\abcdefghijk.txt") do echo %%~snxi
作者:ttj36 | 时间:2008-08-11 11:09
谢谢,好象得不到xx..\这种件夹的短名
作者:slore | 时间:2008-08-11 11:41
可以
作者:kioskboy | 时间:2008-08-11 12:35
FOR /F "delims==" %i IN ('dir /b') DO @echo %~si
作者:HAT | 时间:2008-08-14 23:02 | 标题:Re 6楼
是这个意思吗?
@echo off
for /f "tokens=5 delims= " %%a in ('dir /x ^| findstr xxxxxxxxx.') do echo %%a
作者:ttj36 | 时间:2008-08-15 19:46
楼上的这位大哥,好够象不行哦,不行得到SD..的短名
[ Last edited by ttj36 on 2008-8-15 at 07:48 PM ]
作者:HAT | 时间:2008-08-15 20:47
Q: 为什么不行啊?
A: 去电线杆上找个老军医的手机,他是专治+包治这个的。如果治疗周期较长,建议列出你的测试环境、测试用例、出错信息,供大家帮助你解决问题。
作者:ttj36 | 时间:2008-08-15 22:26
你试试看,我在D盘,你也可以建个MD d:\SD..\ 文件夹,你得到短名看看,
[ Last edited by ttj36 on 2008-8-15 at 10:28 PM ]
作者:HAT | 时间:2008-08-15 22:36
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.
D:\>md sdsdsdsdsd..\
D:\>for /f "tokens=4 delims= " %a in ('dir /x ^| findstr "sdsdsdsdsd."') do @echo %a
SDSDSD~1
作者:ttj36 | 时间:2008-08-15 22:55
for /f "tokens=4 delims= " %a in ('dir /x ^| findstr "d:\sd."') do @echo %a
在BAT里,怎么不行,
而且我得到2个,因为我建了2个这种文件夹一个是,是ASDF. SD.运行长的那个得到一个ASDF~1 ,而运行短的,得到2个,哈哈
[ Last edited by ttj36 on 2008-8-15 at 10:57 PM ]
作者:HAT | 时间:2008-08-15 23:00
cmd里面for的控制变量用一个百分号
bat里面for的控制变量用两个百分号
建议复习一下批处理基础教程^_^
作者:ttj36 | 时间:2008-08-15 23:03
for /f "tokens=4 delims= " %%a in ('dir /x ^| findstr "d:\sd."') do echo %%a
不行呀,哪有问题,请指点一下,只能进入,D目录在运行
for /f "tokens=4 delims= " %%a in ('dir /x ^| findstr "sd."') do echo %%a
而且很不准,只要有SD文字的都会出来,
[ Last edited by ttj36 on 2008-8-16 at 11:23 AM ]
来源:https://www.cn-dos.net/forum/viewthread.php?tid=42136 · 打印时间 2026-08-09 11:35