How can I change file attributes in windows with python?

Asked

Viewed 356 times

3

I am trying to keep a file . txt hidden. How can I do this using python command line?

1 answer

3


In windows you can do so:

import ctypes
FILE_ATTRIBUTE_HIDDEN = 0x02

ret = ctypes.windll.kernel32.SetFileAttributesW('CAMINHO/PARA/FICHEIRO.txt',
                                                FILE_ATTRIBUTE_HIDDEN)
if ret:
    print 'Ficheiro definido para oculto'
else:  # se retornar algum erro
    raise ctypes.WinError()

Withdrawn response from here.

I did not test because I do not have windows, so I’m not sure if it will work, if it does not work say I withdraw the answer from here

Browser other questions tagged

You are not signed in. Login or sign up in order to post.