文件名中的尾随空格 [英] Trailing whitespace in filename

查看:161
本文介绍了文件名中的尾随空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用答案中的批处理脚本为控制台中的某些文本上色.

I tried using a batch-script from this answer to color some text in the console.

不幸的是,我有一些意外的行为,将´3 :s用作string进行了通话,这创建了一个名为:3"的文件,并带有空白.

Unfortunately I had some unintended behaviour, using ´3 :s as string for the call, which created a file named: "┬┤3 ", with a trailing whitespace.

Windows(10)(使用NTFS的硬盘驱动器)以某种方式无法处理文件名中的尾随空格,因此我无法摆脱它.

Windows (10) (harddrive using NTFS) somehow can't handle a trailing whitespace in filenames, therefore I can't get rid of it.

我尝试在Windows资源管理器和Total Commander中使用deleterenamemove-均失败.

I tried using delete, rename, move in the Windows Explorer and Total Commander - all failed.

使用命令提示符:DELMOVE和其他命令会导致找不到"

Using the command prompt: DEL, MOVE and others results in a "cannot find"

使用ATTRIB输出:符号链接┬┤3"的目标不存在"

Using ATTRIB outputs: "target of symbolic link "┬┤3 " does not exist"

要在当前目录中创建这样的文件:

To create such a file in you current directory:

SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do     rem"') do (
    set "DEL=%%a"
)
call :colorEcho 09 "´3 :s  `"
exit
:colorEcho
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1i

推荐答案

对于文件I/O,路径字符串的前缀"\\?\"告诉Windows API禁用所有字符串解析并将其后的字符串直接发送到文件系统.

For file I/O, the "\\?\" prefix to a path string tells the Windows APIs to disable all string parsing and to send the string that follows it straight to the file system.

要在批处理脚本路径中创建文件,请执行以下操作:

To create the file in the batch script path:

> "\\?\%~dp0´3 :s " type nul

要删除:

del "\\?\%~dp0´3 "

:s是NTFS流后缀,对于删除文件的任务可以省略.

The :s is a NTFS stream suffix which can be omitted for the task of deleting the file.

这篇关于文件名中的尾随空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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