Get a long path name (expand ~) on Windows using ctypes. Examples -------- >>> get_long_path_name('c:\\docume~1') 'c:\\\\Documents and Settings'
(path)
| 28 | |
| 29 | if sys.platform == 'win32': |
| 30 | def _get_long_path_name(path): |
| 31 | """Get a long path name (expand ~) on Windows using ctypes. |
| 32 | |
| 33 | Examples |
| 34 | -------- |
| 35 | |
| 36 | >>> get_long_path_name('c:\\docume~1') |
| 37 | 'c:\\\\Documents and Settings' |
| 38 | |
| 39 | """ |
| 40 | try: |
| 41 | import ctypes |
| 42 | except ImportError: |
| 43 | raise ImportError('you need to have ctypes installed for this to work') |
| 44 | _GetLongPathName = ctypes.windll.kernel32.GetLongPathNameW |
| 45 | _GetLongPathName.argtypes = [ctypes.c_wchar_p, ctypes.c_wchar_p, |
| 46 | ctypes.c_uint ] |
| 47 | |
| 48 | buf = ctypes.create_unicode_buffer(260) |
| 49 | rv = _GetLongPathName(path, buf, 260) |
| 50 | if rv == 0 or rv > 260: |
| 51 | return path |
| 52 | else: |
| 53 | return buf.value |
| 54 | else: |
| 55 | def _get_long_path_name(path): |
| 56 | """Dummy no-op.""" |
no outgoing calls
no test coverage detected