Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from aceutil import Log
- log = Log()
- def file_is_hidden(p): #checks if the file is hidden file
- p.replace("/", "\\")
- try:
- if os.name== 'nt':
- attribute = win32api.GetFileAttributes(p) & (win32con.FILE_ATTRIBUTE_HIDDEN | win32con.FILE_ATTRIBUTE_SYSTEM)
- if attribute > 0:
- attribute = True
- else:
- attribute = False
- return attribute
- else:
- return p.startswith('.')
- except Exception as err:
- exc_type, exc_obj, exc_tb = sys.exc_info()
- log.error("sftp.file_is_hidden failed\n%s, %s, %s, %s" %(err, exc_type, exc_obj, traceback.print_tb(exc_tb)))
- def get_files_folders(location): #gets a list of files and a list of folders from a location
- try:
- files=[]
- folders=[]
- objects = [f for f in os.listdir(location) if not self.file_is_hidden(location+f)]
- for i in range(len(objects)):
- objects[i] = str(objects[i])
- for i in objects:
- fileattr = os.lstat(location+i)
- if stat.S_ISDIR(fileattr.st_mode):
- folders.append(i)
- if stat.S_ISREG(fileattr.st_mode):
- files.append(i)
- return folders, files
- except Exception as err:
- exc_type, exc_obj, exc_tb = sys.exc_info()
- log.error("sftp.get_files_folders failed\n%s, %s, %s, %s" %(err, exc_type, exc_obj, traceback.print_tb(exc_tb)))
- return [], []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement