locked
Move-Item and Copy-Item not moving/copying files RRS feed

  • Question

  • Hi Folks,

      I am trying to use PowerShell v4 to move or copy a single file from one directory to another. The script is written using the PowerShell ISE.

      When I execute the move-item command at the command line level, the file gets moved/copied.  However, when I put the same command into the script, it reports the file has been moved, but doing a dir on the Destination directory shows that it has not.

    Move-Item -Path 'c:\convert\fred test.txt' -Destination 'c:\completed'

    The problem occurs when I assign a variable to the full name of the file to be moved.

      eg.   $infile = 'c:\convert\fred test.txt'   followed by Move-Item -Path $infile -Destination 'c:\completed'

    The above two statements execute, but nothing is moved.  I have also used -force but this makes no difference. The issue also occurs with copy-item.

    Anyone have any ideas?

    Sunday, November 15, 2015 11:42 PM

Answers

  • Resolved:-

    Note sure why, but changing my code to:-

     $infile = 'c:\convert\fred test.txt'

     $fileHandle = Get-Item $infile

     Move-Item -Path $fileHandle.FullName -Destination 'c:\completed'

     

    • Marked as answer by AndyW2007 Sunday, November 15, 2015 11:58 PM
    Sunday, November 15, 2015 11:58 PM

All replies

  • Resolved:-

    Note sure why, but changing my code to:-

     $infile = 'c:\convert\fred test.txt'

     $fileHandle = Get-Item $infile

     Move-Item -Path $fileHandle.FullName -Destination 'c:\completed'

     

    • Marked as answer by AndyW2007 Sunday, November 15, 2015 11:58 PM
    Sunday, November 15, 2015 11:58 PM
  • I think you need t change your breakfast cereal. Nothing that you have posted is reasonable. Go back and review your testing. You will find an error.

    \_(ツ)_/

    Monday, November 16, 2015 1:53 AM