diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index bddfa3efa9..056b47b821 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -591,12 +591,11 @@ class DeviceManager(Thread): # {{{ def _save_books(self, paths, target): '''Copy books from device to disk''' for path in paths: - name = path.rpartition(os.sep)[2] + name = ascii_filename(os.path.basename(path)) dest = os.path.join(target, name) if os.path.abspath(dest) != os.path.abspath(path): - f = open(dest, 'wb') - self.device.get_file(path, f) - f.close() + with open(dest, 'wb') as f: + self.device.get_file(path, f) def save_books(self, done, paths, target, add_as_step_to_job=None): return self.create_job_step(self._save_books, done, args=[paths, target],