python - 在 Windows 7 中用冒号 (":") 打开文件名

标签 python linux windows nfs colon

我正在编写一个应该在 Windows 和 Linux 中运行的 Python 应用程序,但我遇到了一个文件命名约定的问题。我需要加载一个名称中有冒号的 JSON 文件。但是,对于 Windows 7,这似乎是不可能的,至少不能直接实现。

这些文件存储在 NFS 驱动器上,因此我们可以在 Windows 7 中看到它,但无法打开它们。

关于如何使用 Python 在 Windows 7 中读取包含冒号的 JSON 文件,有没有人有解决方法?我们有一个可能的解决方法(我们希望避免)是通过 SSH 进入 Linux 机器,回显内容并将其发回。

显然,如果其他人有其他方法会很棒。 Windows XP 能够正常打开和阅读它们 - 这只是 Win 7 的问题。

-edit- 更新:我们发现我们可以通过网络访问我们的 NFS/AFS 服务器。所以我们最终对所有包含无效字符的 JSON 文件使用 urllib2 urlopen。到目前为止似乎运作良好。

最佳答案

引自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.

关于python - 在 Windows 7 中用冒号 (":") 打开文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22976426/

相关文章:

windows - 替换 findstr 命令输出中的字符串

windows - 从exe生成的bat文件中的bash -c不是命令

python - 如何使用 macports 进行全新安装?

python - 高斯过程回归: standard deviation meaning

python - 如何在 Python 中模拟函数以更改默认关键字参数

linux - 堆大小和位置

linux - 带有扭曲数据的图

python - 自动将参数格式化为字符串

linux - 执行附加在可执行文件末尾的机器代码

linux - Linux 下 JavaFX 的默认字体大小与 Windows 上的一样大