转换长文件名短文件名(8.3),使用的cmd.exe [英] Convert long filename to short filename (8.3) using cmd.exe
问题描述
我想一个长文件名转换为Windows上的短文件名(8.3)。
一个批处理文件,命令行参数按预期工作:
的 short.bat 的:
@echo OFF
回声%〜S1
调用 short.bat C:\\ Documents和Settings \\用户\\ NTUSER.DAT
收益 C:\\解决的文〜1 \\ USER \\ NTUSER。 DAT
不过,我不喜欢有一个额外的.bat文件这一点。我宁愿称之为的cmd.exe
从Ruby脚本整个命令。
我怎样才能做到这一点?
作为一个中间步骤我试图硬code在批处理文件的路径,但是,这并不工作:
的 short1.bat 的:
@echo OFF
SET文件名=C:\\ Documents和Settings \\用户\\ NTUSER.DAT
回声%文件名%
回声%〜sfilename%
回声%文件名%
的作品,但回声%〜sfilename%
提供了以下错误:
路径运营商批量参数下使用
替代无效:%〜sfilename%对于有效的格式类型的呼叫/?或FOR /?
如果 short1.bat 的作品,我怎么能转换成一个班轮可与被称为该 cmd.exe的\\ C ...
?
CMD / C为%A中(C:\\ Documents和Settings \\用户\\ NTUSER.DAT)做@echo%〜sA的
I am trying to convert a long filename to a short filename (8.3) on Windows.
A batch-file with a command line argument works as intended:
short.bat:
@echo OFF
echo %~s1
calling short.bat C:\Documents and Settings\User\NTUSER.DAT
returns C:\DOCUM~1\USER\NTUSER.DAT
However, I don't like having an extra .bat-file for this. I would rather call cmd.exe
with the whole command from a ruby script.
How can I do this?
As an intermediate step I tried to hardcode the path in the batch-file, but that does not work:
short1.bat:
@echo OFF
SET filename="C:\Documents and Settings\User\NTUSER.DAT"
echo %filename%
echo %~sfilename%
echo %filename%
works, but echo %~sfilename%
gives the following error:
The following usage of the path operator in batch-parameter
substitution is invalid: %~sfilename%
For valid formats type CALL /? or FOR /?
If short1.bat works, how can I convert this into a one-liner that can be called with cmd.exe \c ...
?
cmd /c for %A in ("C:\Documents and Settings\User\NTUSER.DAT") do @echo %~sA
这篇关于转换长文件名短文件名(8.3),使用的cmd.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!