프로젝트

일반

사용자정보

통계
| 개정판:

hytos / minorTools / xmlTextSearcher.py @ dee50c29

이력 | 보기 | 이력해설 | 다운로드 (2 KB)

1
import os
2

    
3
def finder():
4
    print("finder start")
5
    
6
    targetText = 'UID="8c2a80fd-f16c-490e-b332-dfe0602bafe3">FB<'
7
    path = 'W:\ID2_Project\REB\Temp'
8

    
9
    print("target : " + targetText)
10
    print("path : " + path)
11

    
12
    start = input("start enter 1 : ")
13
    if start != '1':
14
        return
15

    
16
    xmlList = os.listdir(path)
17
    nonXmlList = []
18

    
19
    for index in range(len(xmlList)):
20
        if xmlList[index][-3:] != 'xml':
21
            nonXmlList.append(index)
22

    
23
    nonXmlList.sort(reverse=True)
24
    for index in nonXmlList:
25
        xmlList.pop(index)
26

    
27
    for xml in xmlList:
28
        xmlPath = os.path.join(path, xml)
29
        fw = open(xmlPath, 'r', encoding='utf8')
30
        xmlCon = fw.read()
31
        fw.close()
32

    
33
        number = 0
34
        while xmlCon.find(targetText) != -1:
35
            xmlCon = xmlCon.replace(targetText, '', 1)
36
            number += 1
37

    
38
        if number > 0:
39
            print("drawing : " + xml)
40
            print("count : " + str(number))
41
            print("")
42

    
43

    
44
def changer():
45
    print("changer start")
46
    
47
    originText = 'TSO'
48
    newText = 'FB</ATTRIBUTE>'
49
    path = 'X:\CPChem\Temp'
50
    
51
    print("origin : " + originText)
52
    print("new : " + newText)
53
    print("path : " + path)
54

    
55
    start = input("start enter 1 : ")
56
    if start != '1':
57
        return
58

    
59
    xmlList = os.listdir(path)
60
    nonXmlList = []
61

    
62
    for index in range(len(xmlList)):
63
        if xmlList[index][-3:] != 'xml':
64
            nonXmlList.append(index)
65

    
66
    nonXmlList.sort(reverse=True)
67
    for index in nonXmlList:
68
        xmlList.pop(index)
69

    
70

    
71
    for xml in xmlList:
72
        xmlPath = os.path.join(path, xml)
73
        fw = open(xmlPath, 'r', encoding='utf8')
74
        xmlCon = fw.read()
75
        fw.close()
76

    
77
        xmlCon = xmlCon.replace(originText, newText)
78

    
79
        fw = open(xmlPath, 'w', encoding='utf8')
80
        fw.write(xmlCon)
81
        fw.close()
82

    
83

    
84
if __name__ == '__main__':
85
    selection = input("select fuction(changer = 1, finder = 2) : ")
86
    if selection == '1':
87
        changer()
88
    elif selection == '2':
89
        finder()
클립보드 이미지 추가 (최대 크기: 500 MB)