Quantcast
Channel: User luke - Stack Overflow
Viewing all articles
Browse latest Browse all 31

Answer by luke for Python cross platform hidden file

$
0
0

You could do something like this:

import osimport ctypesFILE_ATTRIBUTE_HIDDEN = 0x02def write_hidden(file_name, data):"""    Cross platform hidden file writer."""    # For *nix add a '.' prefix.    prefix = '.' if os.name != 'nt' else ''    file_name = prefix + file_name    # Write file.    with open(file_name, 'w') as f:        f.write(data)    # For windows set file attribute.    if os.name == 'nt':        ret = ctypes.windll.kernel32.SetFileAttributesW(file_name,                                                        FILE_ATTRIBUTE_HIDDEN)        if not ret: # There was an error.            raise ctypes.WinError()

This has not been tested but should work fine.

Also you may wish to see these other questions that helped me implement this:


Viewing all articles
Browse latest Browse all 31

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>