Search code examples
powershellpowershell-2.0powershell-3.0powershell-4.0

Powershell script to copy and paste file to previous directory


I'm attempting to copy and paste a file to a previous directory without using files paths.

Here's what i mean:

Set-Clipboard File.bat
cd ..
cd ..
cd ..
write-output | get-clipboard

Then I go to check and it's not there, what am i missing??

Thanks.


Solution

  • I think using Set-Clipboard will only copy the name of the file to the clipboard.

    Why not get the file into a variable and the copy that into the new location after you change directories:

    $file = Get-ChildItem .\File.bat
    cd ..
    cd ..
    cd ..
    $file | Copy-Item