-1

I am trying to rename a file and then copy a file to that location, the error I am getting is that

Rename-Item : Cannot rename because item at .... does not exist.

The issue I believe is that the file does not have an extension, so I have something like:

rename-item "\\$serverName\c$\temp\filename" -NewName filename.$currentdate
BenH
  • 9,766
  • 1
  • 22
  • 35
  • 1
    What have you tried, and how has what you've tried failed? Ideally, you should provide a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve) of what you've tried, and include specific information on how it failed, with error messages and/or erroneous output. SO is not a code-writing service; the best questions are those which provide useful information so that those who answer can guide you to devising your own correct answer. See [How to Ask a Good Question](http://stackoverflow.com/help/how-to-ask). – Jeff Zeitlin May 16 '17 at 19:42

1 Answers1

0

Hm, I doubt it is because of no extension. Rename-Item works fine with such files or folders.

In your example, you are missing one \ at the beginning, there should be two of them.

Anyway if you want to be sure, you may use following (you should have variable $currentdate already populated):

$name = '\\$serverName\c$\temp\filename'
Get-Item $name | Rename-Item -NewName "filename.$currentdate"

With those two commands you will see if it fails on Get-Item or on Rename-Item.

Igor
  • 1,349
  • 12
  • 25
  • Thanks Igor , Weirdly it worked piping the path into Rename-Item not sure why it fails without the pipe. Anyways you are timesaver! – Gregory Cooper May 16 '17 at 21:15