Last active
August 29, 2015 13:56
-
-
Save theand/9072553 to your computer and use it in GitHub Desktop.
walks in to directory from cwd, then move all files to parent directory. also check name duplication.
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
| #-*- coding: utf-8 -*- | |
| import os | |
| import os.path | |
| import shutil | |
| for dirpath, dirnames, filenames in os.walk('.'): | |
| for filename in filenames: | |
| if filename == "extract.py" or filename.startswith('.'): | |
| continue | |
| src = os.path.join(dirpath, filename) | |
| if not os.path.exists(src): | |
| print 'no exist : ' + src | |
| continue | |
| if not os.path.isfile(src): | |
| print 'not file : ' + src | |
| continue | |
| dest = '../' + filename | |
| name, ext = os.path.splitext(dest) | |
| i = 1 | |
| while 1: | |
| if os.path.exists(dest): | |
| print 'existing dest' | |
| dest = "%s (%d)%s" %(name, i, ext) | |
| print 'change to %s' % dest | |
| i+=1 | |
| continue | |
| else: | |
| break | |
| shutil.copyfile(src, dest) | |
| print 'copy - ' + filename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment