Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save alkuzad/4b2977b2bc5ca2654b47f065a8b4b471 to your computer and use it in GitHub Desktop.

Select an option

Save alkuzad/4b2977b2bc5ca2654b47f065a8b4b471 to your computer and use it in GitHub Desktop.
pywin32 write file that exceeds 260 chars
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