Opening filenames with colon (“:”) in Windows 7

流过昼夜 提交于 2019-12-03 20:16:03

问题


I am writing a Python app that should run in both Windows and Linux, but am having an issue with one of the filenaming conventions. I need to load a JSON file that has a colon in its name. However, with Windows 7 it doesn't seem to be possible, at least not directly.

These files are stored on a NFS drive thus we are able to see it in Windows 7, but cannot open them.

Does anyone have a workaround as to how it may be possible to read the JSON file containing a colon in Windows 7 using Python? One possible workaround we have (that we'd like to avoid) is to SSH into a Linux box, echo the contents and send it back.

Obviously if anyone else has another method that would be great. Windows XP is able to open them and read them just fine - this is just an issue with Win 7.

-edit- Update: We found out that we can access our NFS/AFS servers through the web. So we ended up using urllib2 urlopen for all the JSON files that contain invalid characters. Seems to be working well so far.


回答1:


To quote from http://support.microsoft.com/kb/289627:

Windows and UNIX operating systems have restrictions on valid characters that can be used in a file name. The list of illegal characters for each operating system, however, is different. For example, a UNIX file name can use a colon (:), but a Windows file name cannot use a colon (:). ...

To enable file name character mapping, create a character translation file and add a registry entry.

For example, the following maps the UNIX colon (:) to a Windows dash (-):

0x3a : 0x2d ; replace client : with - on server

When you have created the file name character translation file, you must specify its name location in the system registry. To register the path and name of the file:

  • Use Registry Editor to locate the following registry key:
  • HKEY_LOCAL_MACHINE\Software\Microsoft\Server For NFS\CurrentVersion\Mapping
  • Edit the CharacterTranslation (REG_SZ) value.
  • Enter the fully qualified path name of the file name character translation file. For example, C:\Sfu\CTrans.txt.


来源:https://stackoverflow.com/questions/22976426/opening-filenames-with-colon-in-windows-7

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