Skip to content

Instantly share code, notes, and snippets.

@D4koon
Created November 26, 2020 11:51
Show Gist options
  • Save D4koon/c1a8939107e2d808d40b6bf6cb54eb73 to your computer and use it in GitHub Desktop.
Save D4koon/c1a8939107e2d808d40b6bf6cb54eb73 to your computer and use it in GitHub Desktop.
Rename files with Python
import os
def list_files(path):
abs_path = os.path.abspath(path)
files = []
for name in os.listdir(abs_path):
it_path = os.path.join(abs_path, name)
if os.path.isfile(it_path):
files.append(it_path)
return files
file_path_list = list_files('.')
for file_path in file_path_list:
if '.c.obj' not in file_path:
continue
filename = os.path.basename(file_path)
dirname = os.path.dirname(file_path)
filename_new = filename.replace('.c.obj', '.o')
filename_new = 'BZE_' + filename_new
os.rename(file_path, os.path.join(dirname, filename_new))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment