转换长文件名​​短文件名(8.3),使用的cmd.exe [英] Convert long filename to short filename (8.3) using cmd.exe

查看:640
本文介绍了转换长文件名​​短文件名(8.3),使用的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆