Skip to content

Instantly share code, notes, and snippets.

@swablueme
Created March 1, 2020 03:02
Show Gist options
  • Select an option

  • Save swablueme/5fcebff2f2fae8736f0f4c9969bc9ac0 to your computer and use it in GitHub Desktop.

Select an option

Save swablueme/5fcebff2f2fae8736f0f4c9969bc9ac0 to your computer and use it in GitHub Desktop.

Revisions

  1. swablueme created this gist Mar 1, 2020.
    18 changes: 18 additions & 0 deletions please_rename_bins.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    import os
    import csv
    OUTPUT_DIRECTORY="out"
    FILELIST_CSV="filelist.csv"

    def rename_bins():
    files=os.listdir(OUTPUT_DIRECTORY)
    with open(FILELIST_CSV) as csvfile:
    reader = csv.DictReader(csvfile)
    dictFilenames={row["Index"]:(row["Filename"], row["Destination"]) for row in reader}
    for file in files:
    filename=os.path.splitext(file)[0]
    new_filename,destination=dictFilenames[filename]
    if not os.path.isdir(os.path.join(OUTPUT_DIRECTORY, destination)):
    os.makedirs(os.path.join(OUTPUT_DIRECTORY, destination))
    os.rename(os.path.join(OUTPUT_DIRECTORY, file), os.path.join(OUTPUT_DIRECTORY, destination, new_filename))
    rename_bins()