I want do delete a file, for ex. 'myfile.txt' that is stored under a hidden folder. Is it possible to do this in python?
thank you
I want do delete a file, for ex. 'myfile.txt' that is stored under a hidden folder. Is it possible to do this in python?
thank you
Yes, just have the path included the hidden folder as follows:
UNIX:
path = "desktop/.hidden_folder/myfile.txt"
WINDOWS (Code from here):
import os
if os.name == 'nt':import win32api, win32con
def file_is_hidden(p):if os.name== 'nt':attribute = win32api.GetFileAttributes(p)return attribute & (win32con.FILE_ATTRIBUTE_HIDDEN | win32con.FILE_ATTRIBUTE_SYSTEM)
else:return p.startswith('.') #linux-osx
[os.remove(f) for f in os.listdir('.') if file_is_hidden(f)]
Then deal with the file as you wish.