You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
: is not technically barred on Windows, since maybe NT? The above test code works fine.
However, the file is not usable in Explorer. It appears as test , so if you try to open or delete it, it doesn't work. It's also not accessible from PowerShell or the Command Prompt. That's not actually because of the colon, but because the filename ends with a space, which is not allowed. While os.unlink('test ') did seem to work, it seems to be stuck in the system somewhere and still shows up in dir or Explorer but can't be opened any more.
What the colon actually does is open an NTFS Alternate Data Stream, and that is intentional. If you remove the space before the colon, then everything works a bit more reasonably:
PS > python
>>> with open('test:broken', 'w') as f:
... f.write('test')
>>> exit()
PS > Get-Item test
Directory: ...\matplotlib
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2024-02-05 6:23 PM 0 test
PS > Get-Item test | Get-Content # Main stream is empty.
PS > Get-Item test | Get-Content -Stream broken # But this alternate stream contains the data we wrote.
test
PS > del test # Works fine here.
While os.unlink('test ') did seem to work, it seems to be stuck in the system somewhere and still shows up in dir or Explorer but can't be opened any more.
Weirdly, if you have just this invalid filename-ending-in-space, then you can't see it correctly with dir /R (you only see test itself), but if you create a valid one as test:broken, then you can see both correctly:
> dir /R "test*"
Directory of ...\matplotlib
2024-02-05 06:38 PM 0 test
4 test:broken:$DATA
2024-02-05 06:38 PM 0 test
4 test :broken:$DATA
2 File(s) 0 bytes
That is, you can see both of them and their Alternate Data Streams.
And it seems del "test*" is able to delete them both.
Do not end a file or directory name with a space or a period. Although the underlying file system may support such names, the Windows shell and user interface does not.
Handling this is beyond our responsibility. This should be reported upstream and cpython itself should decide whether they act on it.
Activity
rcomer commentedon Feb 5, 2024
For me on Ubuntu with TkAgg this code saves out an image with filename
test : diagramm.png. The image itself is as you would expect from the code.timhoffm commentedon Feb 5, 2024
Might be a windows topic since
:is not allowed there.tacaswell commentedon Feb 5, 2024
what does
do?
QuLogic commentedon Feb 5, 2024
:is not technically barred on Windows, since maybe NT? The above test code works fine.However, the file is not usable in Explorer. It appears as
test, so if you try to open or delete it, it doesn't work. It's also not accessible from PowerShell or the Command Prompt. That's not actually because of the colon, but because the filename ends with a space, which is not allowed. Whileos.unlink('test ')did seem to work, it seems to be stuck in the system somewhere and still shows up indiror Explorer but can't be opened any more.What the colon actually does is open an NTFS Alternate Data Stream, and that is intentional. If you remove the space before the colon, then everything works a bit more reasonably:
QuLogic commentedon Feb 5, 2024
Weirdly, if you have just this invalid filename-ending-in-space, then you can't see it correctly with
dir /R(you only seetestitself), but if you create a valid one astest:broken, then you can see both correctly:That is, you can see both of them and their Alternate Data Streams.
And it seems
del "test*"is able to delete them both.timhoffm commentedon Feb 6, 2024
Seems not exactly true. It's allowed but not fully supported 🙄 : https://stackoverflow.com/a/67886889
Edit: Official win32 docs say:
Handling this is beyond our responsibility. This should be reported upstream and cpython itself should decide whether they act on it.
timhoffm commentedon Feb 8, 2024
I'm closing this as we're not going to do any special casing on the Matplotlib side. This is up to cpython: python/cpython#115104.