我一直在创建一个python脚本,它基本上隐藏/取消隐藏Linux环境中的文件和文件夹。这是密码
import os
class unhide_files:
def __init__(self, directory):
self.parent_dir,self.sub_folders,self.files = list(os.walk(directory))[0]
os.chdir(directory)
def general_unhide(self,files):
try:
for f in files:
if "." in f:
os.rename(f,f.replace(".","",True))
except Exception as err:
print(str(err))
def unhide_file(self):
general_unhide(self.files) #unhide_file could not use general_unhide
def unhide_sub_folders(self):
general_unhide(self.sub_folders) #unhide_sub_folders could not use general_unhide
if __name__ == "__main__":
path = input("Enter the directory's path ")
unhid = unhide_files(path)
# testing to see if it works. Directory unhiding is still to
be done
unhid.unhide_file()
# hiding files behaviour is still to be implemented
代码的问题是,除了作为类方法
general_unhide
类中的其他方法无法访问。
有什么特别的原因吗?或者只是一个愚蠢的错误?