Issue34069
Created on 2018-07-08 10:57 by joshuaavalon, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Messages (3) | |||
|---|---|---|---|
| msg321270 - (view) | Author: Joshua Avalon (joshuaavalon) | Date: 2018-07-08 10:57 | |
from shutil import move
from pathlib import Path
a = Path("s")
b = Path("a.txt")
move(b, a)
This will throw AttributeError: 'WindowsPath' object has no attribute 'rstrip'
From the document, it should able to move:
If the destination is an existing directory, then src is moved inside that directory. If the destination already exists but is not a directory, it may be overwritten depending on os.rename() semantics.
If a = Path("s/a.txt"), it does not throw error.
Enviroment:
Window 10
Python 3.7.0
|
|||
| msg321272 - (view) | Author: Eryk Sun (eryksun) * | Date: 2018-07-08 11:33 | |
This issue isn't specific to Windows. It's a bug in shutil._basename:
def _basename(path):
# A basename() variant which first strips the trailing slash, if present.
# Thus we always get the last component of the path, even for directories.
sep = os.path.sep + (os.path.altsep or '')
return os.path.basename(path.rstrip(sep))
It should use `os.fspath(path)` to get the path as a string.
|
|||
| msg321274 - (view) | Author: Berker Peksag (berker.peksag) * | Date: 2018-07-08 12:12 | |
This is a duplicate of bpo-32689. > It should use `os.fspath(path)` to get the path as a string. PR 5393 already does that. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:02 | admin | set | github: 78250 |
| 2018-07-08 12:12:32 | berker.peksag | set | status: open -> closed superseder: shutil.move raises AttributeError if first argument is a pathlib.Path object and destination is a directory nosy:
+ berker.peksag |
| 2018-07-08 11:33:27 | eryksun | set | type: behavior title: Fail to move file in Windows (AttributeError) -> shutil.move fails with AttributeError components: + Library (Lib), - Windows keywords:
+ easy |
| 2018-07-08 10:57:23 | joshuaavalon | create | |