Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening filenames with colon (":") in Windows 7

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.

like image 651
user3517510 Avatar asked Oct 01 '22 02:10

user3517510


1 Answers

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.
like image 101
Joseph Quinsey Avatar answered Oct 13 '22 12:10

Joseph Quinsey