Skip to content

Instantly share code, notes, and snippets.

@giumas
Last active March 9, 2018 03:50
Show Gist options
  • Save giumas/dac61a04517bbb7e307fd5b76eca33b2 to your computer and use it in GitHub Desktop.
Save giumas/dac61a04517bbb7e307fd5b76eca33b2 to your computer and use it in GitHub Desktop.
Rename files in folder by removing a fixed amount of characters (based on a passed string)
import os
def remove_first_part_of_filenames(file_folder, size_str):
for path, subdirs, files in os.walk(file_folder):
for name in files:
print("filename: %s" % name[len(size_str):])
os.rename(os.path.join(path,name), os.path.join(path, name[len(size_str):]))
file_folder = "C:\\Users\\gmasetti\\Dropbox\\ifremer\\renamed\\ascii"
size_str = "survey_supporter_2016-260_"
remove_first_part_of_filenames(file_folder=file_folder, size_str=size_str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment