42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
|
# import os
|
|||
|
#
|
|||
|
# for root, dir, files in os.walk(os.path.expandvars('$HOME') + '/.config/PyQtToDoList/'):
|
|||
|
# for i in files:
|
|||
|
# print(root, dir, files)
|
|||
|
# # print(root)
|
|||
|
# # print(dir)
|
|||
|
import os
|
|||
|
|
|||
|
|
|||
|
# 直接读取配置文件获取ToDo列表来选择备份文件,不再选择同时获取文件和文件夹了
|
|||
|
|
|||
|
def file_name_walk(file_dir):
|
|||
|
for root, dirs, files in os.walk(file_dir):
|
|||
|
# print("root", root) # 当前目录路径
|
|||
|
# print("dirs", dirs) # 当前路径下所有子目录
|
|||
|
# print("files", files) # 当前路径下所有非目录子文件
|
|||
|
print(len(files))
|
|||
|
if dirs and files:
|
|||
|
# print(True)
|
|||
|
print(str(files[0]))
|
|||
|
elif dirs and not files:
|
|||
|
print(dirs[i] for i in range(len(dirs)))
|
|||
|
else:
|
|||
|
print(str(files[j] for j in range(len(files))))
|
|||
|
|
|||
|
# print(False)
|
|||
|
# if
|
|||
|
# if files :
|
|||
|
# print(root + str(dirs[0]) + '/' + str(files[0]))
|
|||
|
# else:
|
|||
|
# print(root + str(files[0]))
|
|||
|
|
|||
|
|
|||
|
file_name_walk(os.path.expandvars('$HOME') + '/.config/PyQtToDoList/')
|
|||
|
# root ./
|
|||
|
# dirs ['test']
|
|||
|
# files ['200-2000(1).txt', '200-2000(2).txt', '200-2000(3).txt', 'getFileName.py']
|
|||
|
# root ./test
|
|||
|
# dirs []
|
|||
|
# files ['test.txt']
|