Найти - Пользователи
Полная версия: ошибки при os.rename в linux
Начало » Python для экспертов » ошибки при os.rename в linux
1
pythonwin
Добрый день!

пожалуйста, подскажите как обойти проблему с пробелами в имена каталога при перемещении/переименовании?
import os
old="/home/user1/progs/test1/f.zip"
new = '/media/MY USB DISC/f.zip'
os.rename(old, new)

Traceback (most recent call last):
File “<stdin>”, line 1, in ?
OSError: Invalid cross-device link


пробовал
new = “/media/'MY USB DISC'/f.zip”
new = “/media/MY/040USB/040DISC/f.zip”
new = “/'media/MY USB DISC'/f.zip”
pythonwin
ошибка найдена - в debian rename может сгенерировать ошибку если перемешать с одной файловой системы на другую
http://www.python.org/doc/2.4/lib/os-file-dir.html

Rename the file or directory src to dst. If dst is a directory, OSError will be raised. On Unix, if dst exists and is a file, it will be removed silently if the user has permission. The operation may fail on some Unix flavors if src and dst are on different filesystems. If successful, the renaming will be an atomic operation (this is a POSIX requirement). On Windows, if dst already exists, OSError will be raised even if it is a file; there may be no way to implement an atomic rename when dst names an existing file. Availability: Macintosh, Unix, Windows.
OlDer
Используй move из shutil. Он сам когда нужно будет использовать rename, а когда нужно - copy/delete.
pythonwin
OlDer
Используй move из shutil. Он сам когда нужно будет использовать rename, а когда нужно - copy/delete.
спасибо - помогло :)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB