How can I make a file hidden on Windows?
Question:
On windows you can right-click a file, click on properties and select hidden. How can I do this to a file in python?
Answers:
If this is for Windows only:
import win32con, win32api
file = 'myfile.txt' #or full path if not in same directory
win32api.SetFileAttributes(file,win32con.FILE_ATTRIBUTE_HIDDEN)
If you don’t want/don’t have access to win32 modules you can still call attrib
:
import subprocess
subprocess.check_call(["attrib","+H","myfile.txt"])
for a full cross-platform solution see Python cross platform hidden file
this is the easy way
import os
os.system( "attrib +h myFile.txt" )
hide file ‘+h’
show file ‘-h’
myFile.txt can be the full path to your file
On windows you can right-click a file, click on properties and select hidden. How can I do this to a file in python?
If this is for Windows only:
import win32con, win32api
file = 'myfile.txt' #or full path if not in same directory
win32api.SetFileAttributes(file,win32con.FILE_ATTRIBUTE_HIDDEN)
If you don’t want/don’t have access to win32 modules you can still call attrib
:
import subprocess
subprocess.check_call(["attrib","+H","myfile.txt"])
for a full cross-platform solution see Python cross platform hidden file
this is the easy way
import os
os.system( "attrib +h myFile.txt" )
hide file ‘+h’
show file ‘-h’
myFile.txt can be the full path to your file