文件名中的尾随空格

Trailing whitespace in filename

我尝试使用 this answer 中的批处理脚本为控制台中的一些文本着色。

不幸的是,我有一些意想不到的行为,使用 ´3 :s 作为调用的 string,它创建了一个名为“┬┤3”的文件,带有尾随空格。

Windows (10)(使用 NTFS 的硬盘)不知何故无法处理文件名中的尾随空格,因此我无法摆脱它。


我尝试在 Windows Explorer 和 Total Commander 中使用 deleterenamemove - 都失败了。

使用命令提示符:DELMOVE 和其他命令会导致 "cannot find"

使用ATTRIB输出:"target of symbolic link "┬┤3“不存在”


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

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

Win32 File Namespaces

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.

在批处理脚本路径中创建文件:

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

要删除:

del "\?\%~dp0´3 "

:s 是一个 NTFS 流后缀,删除文件时可以省略。