Skip to content

Instantly share code, notes, and snippets.

@daguiam
Created August 1, 2018 08:46
Show Gist options
  • Save daguiam/e8f311744fd29ee5f171a98f4db5ce8b to your computer and use it in GitHub Desktop.
Save daguiam/e8f311744fd29ee5f171a98f4db5ce8b to your computer and use it in GitHub Desktop.
Renaming files with a sequence number format (001, 002, etc)
# Reducing sample names of QN61 by 1 value to match QN62, QN63 and the DieMap
root_dir = os.path.abspath(path_string)
files = os.listdir(root_dir)
prefix = ".csv"
files = [file for file in files if prefix in file]
for file in files:
number = int(file[1:4])-1
# print("%03d"%number)
newfile = "S%03d.csv"%number
# print(newfile)
os.rename(os.path.join(root_dir,file),os.path.join(root_dir,newfile))
print("saved to %s"%newfile)
# print(os.path.join(root_dir,file))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment