From 71c57a7b150447e6120e0a7e2735dfe827975512 Mon Sep 17 00:00:00 2001 From: David Pugnasse Date: Wed, 10 Aug 2011 10:46:59 +0200 Subject: improved renaming doesn't overwrite files creates directories on rename --- ranger/core/actions.py | 2 +- ranger/defaults/commands.py | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ranger/core/actions.py b/ranger/core/actions.py index 8cecf077..7bb80343 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -830,6 +830,6 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware): src = src.path try: - os.rename(src, dest) + os.renames(src, dest) except OSError as err: self.notify(err) diff --git a/ranger/defaults/commands.py b/ranger/defaults/commands.py index ad3fa0e5..319c5cef 100644 --- a/ranger/defaults/commands.py +++ b/ranger/defaults/commands.py @@ -632,11 +632,20 @@ class rename(Command): def execute(self): from ranger.fsobject import File + from os import access + from os.path import join + line = parse(self.line) - if not line.rest(1): + new_name = line.rest(1) + + if not new_name: return self.fm.notify('Syntax: rename ', bad=True) - self.fm.rename(self.fm.env.cf, line.rest(1)) - f = File(line.rest(1)) + + if access(new_name, os.F_OK): + return self.fm.notify("Can't rename: file already exists!", bad=True) + + self.fm.rename(self.fm.env.cf, new_name) + f = File(new_name) self.fm.env.cwd.pointed_obj = f self.fm.env.cf = f -- cgit 1.4.1-2-gfad0