fish-station/Tools/_sunrise/remove_spaces.py

18 lines
707 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
audio_dir_path = 'Resources/Audio/_Sunrise/TapePlayer/Tracks'
files = os.listdir(audio_dir_path)
for filename in files:
new_filename = filename.replace(' ', '_')
if new_filename != filename:
old_file_path = os.path.join(audio_dir_path, filename)
new_file_path = os.path.join(audio_dir_path, new_filename)
try:
os.rename(old_file_path, new_file_path)
print(f'Переименован: {filename} -> {new_filename}')
except FileExistsError:
print(f'Файл {new_filename} уже существует')
print('Все пробелы в названиях файлов заменены на подчеркивания.')