I am trying to make a python program that creates and writes in a txt file. the program works, but I want it to cross the "hidden" thing in the txt file's properties, so that the txt can't be seen without using the python program I made. I have no clues how to do that, please understand I am a beginner in python.
Asked
Active
Viewed 320 times
0
-
If you want it to only be used by your python program you should consider putting it in zip and password protecting it. Hiding it is simple but it won't really protect your file. – Ninad Gaikwad Sep 17 '18 at 15:48
2 Answers
0
I'm not 100% sure but I don't think you can do this in Python. I'd suggest finding a simple Visual Basic script and running it from your Python file.

Shiney
- 1
- 1
- 2
-
ok thanks for trying to help. I can't use a visual basic script I have to only use python – itisku Sep 17 '18 at 16:16
0
Assuming you mean the file-properties, where you can set a file as "hidden". Like in Windows as seen in screenshot below:
Use operating-system's command-line from Python
For example in Windows command-line attrib +h Secret_File.txt
to hide a file in CMD.
import subprocess
subprocess.run(["attrib", "+h", "Secret_File.txt"])
See also: How to execute a program or call a system command?
Directly call OS functions (Windows)
import ctypes
path = "my_hidden_file.txt"
ctypes.windll.kernel32.SetFileAttributesW(path, 2)
See also: Hide Folders/ File with Python
Rename the file (Linux)
import os
filename = "my_hidden_file.txt"
os.rename(filename, '.'+filename) # the prefix dot means hidden in Linux
See also: How to rename a file using Python

hc_dev
- 8,389
- 1
- 26
- 38