Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This checks for an existing path+file exists.
- # so the full file path intending to be written
- # /Volumes/Drive/Directory/File.ext
- #
- #If 'File.ext' already exists at /Volume/Drive/Directory
- # The next would be:
- # /Volumes/Drive/Directory/File01.ext
- # /Volumes/Drive/Directory/File02.ext
- # /Volumes/Drive/Directory/File03.ext
- #
- # I want to increment the directory path instead of
- # the filename instead:
- # /Volumes/Drive/Directory01/File.ext
- # ...if that exists then next:
- # /Volumes/Drive/Directory02/File.ext
- #
- # Any takers? :)
- # Thanks!
- def _rename(self, old_filename, metadata):
- new_filename, ext = os.path.splitext(
- self.make_filename(old_filename, metadata))
- if old_filename == new_filename + ext:
- return old_filename
- new_dirname = os.path.dirname(new_filename)
- if not os.path.isdir(new_dirname):
- os.makedirs(new_dirname)
- tmp_filename = new_filename
- i = 1
- while (not pathcmp(old_filename, new_filename + ext)
- and os.path.exists(new_filename + ext)):
- new_filename = "%s (%d)" % (tmp_filename, i)
- i += 1
- new_filename = new_filename + ext
- log.debug("Moving file %r => %r", old_filename, new_filename)
- shutil.move(old_filename, new_filename)
- return new_filename
Advertisement
Add Comment
Please, Sign In to add comment