79811968

Date: 2025-11-07 05:12:10
Score: 1
Natty:
Report link

@ShaunLuttin's answer states

From the docs, it says of -NewName<String>

Enter only a name, not a path and name. If you enter a path that is different from the path that is specified in the Path parameter, Rename-Item generates an error.

That is not accurate. Almost, but not quite. What is actually implemented is:

If you enter a path that is different from the fully resolved path that is specified in the Path parameter

IE two specified relative paths that resolve to the same actual path still fails. Sigh.

This code demonstrates:

# https://stackoverflow.com/questions/29636103/rename-fails-because-it-represents-a-path-or-device-name
cd c:\tmp\post29636103

# no path
Rename-Item some\long\path\fileName.txt newName.txt
# works

# same relative path
Rename-Item some\long\path\fileName_2.txt some\long\path\newName_2.txt
# fails
# Rename-Item : Cannot rename the specified target, because it represents a path or device name.

# same (but fully specified/resolved) path
Rename-Item some\long\path\fileName_2.txt c:\tmp\post29636103\some\long\path\newName_2.txt
# works
Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @ShaunLuttin's
  • Low reputation (0.5):
Posted by: john v kumpf