본문 바로가기
Study/Python

[Python3] Extract String from File in Directory

by Becoming a Hacker 2022. 3. 18.
반응형

Extract String from File in Directory Code

import re
import os

directory = r"./" # directory path

files = os.listdir(directory)
for f1 in files:
    filename = os.path.join(directory, f1)
    with open(filename, encoding='Latin-1') as f2:
        str_list = re.findall("[A-Za-z0-9/\-:;.,_$%'!()[\]<> \#@]+", f2.read())
        with open(os.path.join(directory,"strings.txt"),"a+") as save_file:
            for str in str_list:
                save_file.write(str+"\n")
print("Complete")

'Study > Python' 카테고리의 다른 글

Django란?  (0) 2022.07.10
[Windows] Sublimetext input() Not Working  (0) 2022.04.15
IDA Python 정리 (IDA 7.5 이상 사용 가능)  (0) 2022.03.11
[Python3] Tcp Socket Proxy tool  (0) 2022.03.10
[Python] resolve "failed to create process." issue  (0) 2021.11.05

댓글