1,105,406 Community Members

How to hide a file using python?

Member Avatar
mahela007
Posting Whiz in Training
214 posts since Feb 2009
Reputation Points: 6 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
rikxik
Newbie Poster
17 posts since Mar 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 
fn = 'c:\\file.txt'
p = os.popen('attrib +h ' + fn)
t = p.read()
p.close()
Member Avatar
mahela007
Posting Whiz in Training
214 posts since Feb 2009
Reputation Points: 6 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
rikxik
Newbie Poster
17 posts since Mar 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
Norbert X
Junior Poster in Training
87 posts since Feb 2009
Reputation Points: 42 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
jlm699
Veteran Poster
1,104 posts since Jul 2008
Reputation Points: 320 [?]
Q&As Helped to Solve: 295 [?]
Skill Endorsements: 0 [?]
 
0
 

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...

Member Avatar
mahela007
Posting Whiz in Training
214 posts since Feb 2009
Reputation Points: 6 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

thanks

Member Avatar
ravivr
Newbie Poster
1 post since Jun 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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/

Member Avatar
mahela007
Posting Whiz in Training
214 posts since Feb 2009
Reputation Points: 6 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article