locked
Is it really the only way to copy a specific file to a new space eg for backup RRS feed

  • Question

  • Is it really the only way to copy a specific file to a new space eg for backup

    New-Item "C:\work\to\backup\Web.config" -Force
    Copy-Item "C:\work\from\Web.config" -Destination "C:\work\to\backup\Web.config" -Force

    can I not do that in a copy-item funktion

    -Destination folder does not exist at script startup

    Friday, January 12, 2018 2:09 PM

Answers

  • ooops ... now I see my mistake ... I thought it was about the missing destination folder .... ;-)   hihihi  :-D

    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    • Marked as answer by www.LarsOle.dk Monday, January 22, 2018 12:33 PM
    Friday, January 12, 2018 2:45 PM

All replies

  • You could use robocopy instead but with pure Powershell that's the way it's designed. If the destination folder does not exist yet you have to create it before you copy something to it.

    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    Friday, January 12, 2018 2:16 PM
  • This is all you need:

    Copy-Item C:\work\from\Web.config -Destination C:\work\to\backup

    No target name required and no New-Item.

    If can be shortened for quick use:

    copy C:\work\from\Web.config C:\work\to\backup

    Take some time to learn how the Windows file system works.  There are many books and blogs on the details of how to use the file system.


    \_(ツ)_/



    • Edited by jrv Friday, January 12, 2018 2:21 PM
    Friday, January 12, 2018 2:19 PM
  • ooops ... now I see my mistake ... I thought it was about the missing destination folder .... ;-)   hihihi  :-D

    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    • Marked as answer by www.LarsOle.dk Monday, January 22, 2018 12:33 PM
    Friday, January 12, 2018 2:45 PM