Trailing whitespace in filename

こ雲淡風輕ζ 提交于 2019-12-11 07:15:06

问题


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

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) (harddrive using NTFS) somehow can't handle a trailing whitespace in filenames, therefore I can't get rid of it.


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

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

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

回答1:


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.

To create the file in the batch script path:

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

To remove:

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

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



来源:https://stackoverflow.com/questions/48439697/trailing-whitespace-in-filename

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!