Is there any way to hide folders/ files with Python?
I'm working a huge project (a vulnerability scanner). The project creates a lot of files and folders. Therefore the question, is there any way to make a script that hides files and folders?
Is there any way to hide folders/ files with Python?
I'm working a huge project (a vulnerability scanner). The project creates a lot of files and folders. Therefore the question, is there any way to make a script that hides files and folders?
If you don't want to go to the hassle of using pywin32 you can call SetFileAttributes with ctypes in the standard library.
ctypes.windll.kernel32.SetFileAttributesW(path, 2)
path
must be a unicode string type as this is the unicode version of SetFileAttributes. The constant 2 is from this page (FILE_ATTRIBUTE_HIDDEN). I imagine that there's no way to get nice constant names out of ctypes so you'll have to look them up yourself.
If this is for Windows:
http://code.activestate.com/recipes/303343/
Summary: import win32api, win32con, os win32api.SetFileAttributes(filename,win32con.FILE_ATTRIBUTE_HIDDEN)
If for Unix:
filename = "." + filename
for file address in filename use r as prefix because address contains back slashes... eg r"c:...\file"
import tempfile
See the documentation.
Here "hidden file" means "The file is readable and writable only by the creating user ID." i.e., the meaning is "hide file from other users".
If you can put your data in a DBM style file you will only have a single data file.
http://docs.python.org/library/anydbm.html
Instead of filenames you would use keys into the db and the content of your file would be found by indexing into the db.
This requires that your individual files are small enough to be easily fully loaded each time you need access to part of them. If they are big then consider splitting them and using the DBM keys to access chunks of it. For example if "example.txt" contains many lines and you want to be able to access each line individually you could store it as db["example.txt/l1"]
…db["example.txt/l42"]
.
there is possible (at least with linux and ext fs) to open/create file and keep only file handler available for read/write operations from active process, but no other process can see that file listed in directories or anywhere.
it's depends on OS and filesystem, and it is just simple like:
fh = open("data", "w+")
os.system("unlink data")
fh.write(sth)
...
very volatile file and a bit tricky solution, but works fine.