You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lua/plenary/path.lua
+56-13Lines changed: 56 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -515,30 +515,73 @@ function Path:rmdir()
515
515
uv.fs_rmdir(self:absolute())
516
516
end
517
517
518
+
---Rename this file or directory to the given target, and return a new Path instance pointing to target. On Unix, if target exists and is a file, it will be replaced silently if the user has permission. On Windows, if target exists, FileExistsError will be raised. target can be either a string or another path object:
519
+
---@genericT:Path
520
+
---@paramopts{ new_name: Path|string }
521
+
---@returnT
518
522
functionPath:rename(opts)
523
+
-- TODO: For reference, Python's `Path.rename()` actually says/does this:
524
+
--
525
+
-- > On Unix, if target exists and is a file, it will be replaced silently
526
+
-- > if the user has permission.
527
+
-- >
528
+
-- > On Windows, if target exists, FileExistsError will be raised. target
529
+
-- > can be either a string or another path object.
530
+
--
531
+
-- The behavior here may differ, as an error will be thrown regardless.
532
+
533
+
localself_lstat, new_lstat, status, errmsg
519
534
opts=optsor {}
520
-
ifnotopts.new_nameoropts.new_name=="" then
521
-
error"Please provide the new name!"
522
-
end
535
+
assert(opts.new_nameandopts.new_name~="", "Please provide the new name!")
536
+
self_lstat, errmsg=uv.fs_lstat(self.filename)
537
+
538
+
-- Cannot rename a non-existing path (lstat is needed here, `Path:exists()`
0 commit comments