forked from pampam8023/macOS-and-GCPjupyter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.ipynb
101 lines (101 loc) · 2.63 KB
/
.ipynb
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"# 1. 获取一个要重命名的文件夹的名字\n",
"folder_name = input(\"请输入要重命名的文件夹:\")\n",
"\n",
"# 2. 获取那个文件夹中所有的文件名字\n",
"file_names = os.listdir(folder_name)\n",
"\n",
"# 第1中方法\n",
"# os.chdir(folder_name)\n",
"\n",
"# 3. 对获取的名字进行重命名即可\n",
"# for name in file_names:\n",
"# print(name)\n",
"# os.rename(name,\"[京东出品]-\"+name)\n",
"i = 1 # 可以让每个文件名字都不一样\n",
"\n",
"for name in file_names:\n",
" print(name)\n",
" print(name.split('[京东出品]-')[-1])\n",
" name1 = name.split('[京东出品]-')[-1]\n",
" old_file_name = \"./\" + folder_name + \"/\" + name\n",
" new_file_name = \"./\" + folder_name + \"/\" + str(i) + \"[京东出品]-\" + name1\n",
" os.rename(old_file_name, new_file_name)\n",
" i += 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"\n",
"path = ('./ttt/')\n",
"\n",
"#获取该目录下所有文件,存入列表中\n",
"f =os.listdir(path)\n",
"print(len(f))\n",
"\n",
"#删除.jpg后缀,只要文件名前13位数字\n",
"newarr = []\n",
"for i in f:\n",
" x = i[0:13]\n",
" newarr.append(x)\n",
" \n",
"#文件名从大到小排序\n",
"newarr.sort(reverse=True)\n",
"\n",
"\n",
"\n",
"n = 1\n",
"\n",
"for i in range(len(newarr)):\n",
" oldname = path + newarr[i] +'.jpg'\n",
" #第0,2,4...偶数位是反面,命名+b , 奇数位是正面,命名+a\n",
" if i % 2 == 0 :\n",
" newname = path + str(n) + 'b' + '.jpg'\n",
" else:\n",
" newname = path + str(n) + 'a' + '.jpg'\n",
" n = n + 1\n",
"\n",
" #用os模块中的rename方法对文件改名\n",
" os.rename(oldname,newname)\n",
" print(oldname,'======>',newname)\n",
" "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}