mrdigital
mrdigital

Reputation: 79

Hidden file attributes

In Python, how do you make a particular file hidden? Or how do you set the file attribute as 'hidden' without using external API's/modules such as WIN32API, etc.

Surely there is something in the standard libraries? As the os module does allow to set the "read" and 'write' attributes, it is very strange that there is no mention in the os docs of 'hidden'...

Upvotes: 2

Views: 4003

Answers (2)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798686

Not all operating systems have the concept of "hidden" for files, and most (even with all the different versions of Windows 7 etc. there are still more forms of *nix out there than Windows) indicate it by having the first character of the filename be a period (.). On the OSes that do support it you must use some external API or tool in order to set it on the file.

Upvotes: 2

Hitesh Dharamdasani
Hitesh Dharamdasani

Reputation: 862

Use

fn = 'c:\\file.txt'
p = os.popen('attrib +h ' + fn)
t = p.read()
p.close()

Upvotes: 4

Related Questions