-
Notifications
You must be signed in to change notification settings - Fork 6
/
生成所有文件夹名和文件名到文件夹名.txt(9个模式)(拖拽,仅多个文件夹).py
55 lines (50 loc) · 2.25 KB
/
生成所有文件夹名和文件名到文件夹名.txt(9个模式)(拖拽,仅多个文件夹).py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# encoding:utf-8
# https://github.com/wangandi520/andyspythonscript
import sys
from pathlib import Path
def writefile(filereadlines, fileName):
newfile = open(fileName + '.txt', mode='w', encoding='UTF-8')
newfile.writelines(filereadlines)
newfile.close()
def main(inputPath):
del inputPath[0]
# setType运行模式:
# 1=输出所有文件名和文件夹名,使用绝对路径
# 2=输出所有文件名和文件夹名,使用相对路径
# 3=仅输出文件夹名,使用绝对路径
# 4=仅输出文件夹名,使用相对路径
# 5=仅输出文件名,使用绝对路径
# 6=仅输出文件名,使用相对路径
# 7=仅输出文件夹名,无路径
# 8=仅输出文件名和扩展名,无路径
# 9=仅输出文件名,无路径无扩展名
setType = 9
for aPath in inputPath:
allData = []
if Path.is_dir(Path(aPath)):
for eachPath in Path(aPath).glob('**/*'):
if setType == 1:
allData.append(str(Path(aPath).joinpath(eachPath)) + '\n')
if setType == 2:
allData.append(str(eachPath.relative_to(aPath)) + '\n')
if setType == 3 and Path.is_dir(eachPath):
allData.append(str(Path(aPath).joinpath(eachPath)) + '\n')
if setType == 4 and Path.is_dir(eachPath):
allData.append(str(eachPath.relative_to(aPath)) + '\n')
if setType == 5 and Path.is_file(eachPath):
allData.append(str(Path(aPath).joinpath(eachPath)) + '\n')
if setType == 6 and Path.is_file(eachPath):
allData.append(str(eachPath.relative_to(aPath)) + '\n')
if setType == 7 and Path.is_dir(eachPath):
allData.append(str(eachPath.name) + '\n')
if setType == 8 and Path.is_file(eachPath):
allData.append(str(eachPath.name) + '\n')
if setType == 9 and Path.is_file(eachPath):
allData.append(str(eachPath.stem) + '\n')
writefile(allData, Path(aPath).name)
if __name__ == '__main__':
try:
if len(sys.argv) >= 2:
main(sys.argv)
except IndexError:
pass