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
|
#geojsonを公共座標と任意座標でフォルダ分けする
import shutil
import re
import glob
import os
# パターンファイルの作成
pattern1 = '公共座標'
pattern2 = '任意座標'
# ファイルパス
path_locate = r"Z:\公図"
# ファイルの取得
file_list = glob.glob(os.path.join(path_locate,"*.geojson"))
# 保存フォルダを作成する
dir_pattern1 = os.path.join(path_locate,pattern1)
if not os.path.isdir(dir_pattern1):
os.makedirs(dir_pattern1)
print(pattern1,"フォルダを作成しました。")
dir_pattern2 = os.path.join(path_locate,pattern2)
if not os.path.isdir(dir_pattern2):
os.makedirs(dir_pattern2)
print(pattern2,"フォルダを作成しました。")
dir_pattern3 = os.path.join(path_locate,"未分類")
if not os.path.isdir(dir_pattern3):
os.makedirs(dir_pattern3)
print("未分類フォルダを作成しました。")
for textfile in file_list:
f = open(textfile, encoding="utf-8")
lines = f.readlines()
f.close
if re.search(pattern1,"".join(lines)):
print(textfile,"-> 公共座標")
shutil.copy(textfile,dir_pattern1)
elif re.search(pattern2,"".join(lines)):
print(textfile,"-> 任意座標")
shutil.copy(textfile,dir_pattern2)
else:
print(textfile,"-> 未分類")
shutil.copy(textfile,dir_pattern3)
|