Occasionally I need to make files in certain folder using python. To minimize the clutter which such files might cause I would like to make them hidden. It's pretty easy to do this using windows explorer but I have to do it manually for every file which my script creates. Is there any way to specify in python that a certain file which was created should be hidden/invisible in windows explorer?
thanks

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

could you please explain that bit of code? I'm a newbie programmer so I'm not very good at interpreting code

attrib is commandline way to change file attributes (like dos command). On a DOS command window do, "help attrib" to see the options.

from the title, it kind of sounds like you're hiding something on your computer from the cops. basically the code opens the document you type in, changes it to become hidden then closes it.

os.popen allows you to execute a system call from within Python, as if you were in the command line. Note that this method would only work on Windows platforms...

thanks

Occasionally I need to make files in certain folder using python. To minimize the clutter which such files might cause I would like to make them hidden. It's pretty easy to do this using windows explorer but I have to do it manually for every file which my script creates. Is there any way to specify in python that a certain file which was created should be hidden/invisible in windows explorer?
thanks

There's a good blog about it + code examples for that at:

http://chaptersinwebsecurity.blogspot.com/2009/02/hiding-files-in-windows.html

http://chaptersinwebsecurity.blogspot.com/2009/04/python-and-alternate-data-streams.html

You may download the source Python fo hide.py / unhide.py at:
http://www.sn3akers.com/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.