Created
July 20, 2023 07:18
-
-
Save Hosuke/f8360eaaa565cc4041ca40823f5fd187 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
# 获取当前工作目录 | |
directory = os.getcwd() | |
# 遍历目录及其所有子目录下的所有文件 | |
for dirpath, dirnames, filenames in os.walk(directory): | |
for filename in filenames: | |
# 只处理.sql文件 | |
if filename.endswith('.sql'): | |
filepath = os.path.join(dirpath, filename) | |
# 读取文件内容 | |
with open(filepath, 'r') as file: | |
filedata = file.read() | |
# 使用正则表达式替换日期,忽略大小写 | |
filedata = re.sub(r"DATE\s+'([^']*)'", r"TIMESTAMP '\1'", filedata, flags=re.IGNORECASE) | |
# 将修改后的内容写回文件 | |
with open(filepath, 'w') as file: | |
file.write(filedata) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment