Created
June 15, 2019 20:26
-
-
Save alkuzad/4b2977b2bc5ca2654b47f065a8b4b471 to your computer and use it in GitHub Desktop.
pywin32 write file that exceeds 260 chars
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import win32file | |
| def write260(path, content): | |
| handle = None | |
| try: | |
| # http://docs.activestate.com/activepython/2.6/pywin32/win32file__CreateFileW_meth.html | |
| # http://timgolden.me.uk/pywin32-docs/win32file__CreateFileW_meth.html | |
| handle = win32file.CreateFileW( | |
| path, | |
| win32file.GENERIC_WRITE, | |
| 0, | |
| None, | |
| win32file.CREATE_NEW, | |
| win32file.FILE_ATTRIBUTE_NORMAL, | |
| None, | |
| None, | |
| None, | |
| None | |
| ) | |
| win32file.WriteFile(handle, content) #http://timgolden.me.uk/pywin32-docs/win32file__WriteFile_meth.html | |
| finally: | |
| if handle is not None: | |
| handle.close() | |
| if __name__ == '__main__': | |
| write260('\\\\?\\C:\\Path\\to\\file\\exceeds\\260chars', b'Test content') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment