import os def create_txt_for_mp3(): for file in os.listdir(): if file.endswith(".mp3"): file_name_without_extension, _ = os.path.splitext(file) with open(file_name_without_extension + '.txt', 'w') as f: f.write(file_name_without_extension) create_txt_for_mp3()