Created
December 8, 2009 18:51
-
-
Save tstone/251885 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
from dirsearch import DirSearch | |
# Global variables | |
PREFIX = '' | |
# | |
# Print the basic help to the screen | |
# | |
def print_help(): | |
print 'Recursive Prefix Rename Command (Windows):' | |
print '-------------------------------' | |
print 'Automates the adding of a prefix to all filenames' | |
print 'Syntax:' | |
print '-------------------------------' | |
print 'rrename.py [dir] [prefix]' | |
# | |
# Called each time the DirSearch files a new file | |
# | |
def search_callback(item): | |
filename = os.path.basename(item) | |
if filename.find(PREFIX) != 0: | |
new_name = os.path.join(os.path.dirname(item), '%s%s' % (PREFIX, filename)) | |
os.rename(item, new_name) | |
# | |
# Script entry point | |
# | |
if __name__ == '__main__': | |
# Make sure at least 2 arguments besides script name was given | |
if len(sys.argv) < 3 : | |
print_help() | |
else: | |
if '-help' or '/help' in sys.argv: | |
print_help() | |
else: | |
PREFIX = sys.argv[2] | |
d = DirSearch(sys.argv[1], show_output=True) | |
d.search(search_callback) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment