python在windows创建的文件,换成linux系统格式
dos2unix.exe的下载(下载的文件放入路径下:C:\Windows\System32)
链接:https://pan.baidu.com/s/10fC2tfvUtbh-axJ21cj_Xw?pwd=m3zc
提取码:m3zc
批量修改文件格式
import subprocess# 文件路径列表
file_paths = ['./shells/kq/02nginx_close.sh','./shells/kq/03nginx_kaiqi.sh','./shells/qcgb/02nginx_close.sh','./shells/qcgb/03nginx_kaiqi.sh','./shells/xskq/02nginx_close.sh','./shells/xskq/03nginx_kaiqi.sh'
]# 循环处理每个文件
for file_path in file_paths:try:result = subprocess.run(['dos2unix', file_path], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)print(f"Processed {file_path} successfully.")except subprocess.CalledProcessError as e:print(f"Error processing {file_path}: {e.stderr.decode()}")