#!/usr/bin/python # # When switching from individual file torrents to a torrent of many files, # the filenames are usually down-cased and '-' becomes '.'. This script # will rename all files in the current directory to follow these rules. # # To prevent random rewriting of uninteded files, prompts are used. # # ### in the future, maybe a switch to skip prompts? dangerous! # import os def main(prompt=True): one_renamed = False files = os.listdir('.') for fname in files: renamed = fname.lower().replace('-', '.') if fname == renamed: continue print 'RENAME:', fname print ' to:', renamed if prompt: answer = raw_input(' (y,n,Q,!): ').strip().lower() if answer == 'q' or not answer: return if answer == 'n': continue if answer == '!': prompt = False elif answer != 'y': print ' ... unknown response. SKIPPING.' continue # Only here if !prompt, or answered with ! or y. os.rename(fname, renamed) print ' ... done.' one_renamed = True if not one_renamed: print 'NOTICE: no files to rename.' if __name__ == '__main__': main()