31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
import os
|
|
import re
|
|
import argparse
|
|
|
|
parser = argparse.ArgumentParser(description="Очистка имён файлов 1С интеграционных объектов")
|
|
parser.add_argument("path", nargs="?", default=os.getcwd(), help="Путь к каталогу (по умолчанию: текущий)")
|
|
args = parser.parse_args()
|
|
|
|
root = args.path
|
|
|
|
for dirpath, _, files in os.walk(root):
|
|
for fname in files:
|
|
# 1. Удалить все .json файлы
|
|
if fname.endswith(".json"):
|
|
os.remove(os.path.join(dirpath, fname))
|
|
print(f"Deleted: {fname}")
|
|
continue
|
|
|
|
# 2. Сменить [Code].ext -> .bsl
|
|
if " [Code].ext" in fname:
|
|
new_name = fname.replace(" [Code].ext", ".bsl")
|
|
# 3. Убрать префикс [...] в начале имени
|
|
elif fname[0] == "[":
|
|
new_name = re.sub(r"^\[[^\]]*\]\s*", "", fname)
|
|
else:
|
|
continue
|
|
|
|
old_path = os.path.join(dirpath, fname)
|
|
new_path = os.path.join(dirpath, new_name)
|
|
os.rename(old_path, new_path)
|
|
print(f"Renamed: {fname} -> {new_name}") |