locked
how to move-item with folder structure RRS feed

  • Question

  • I am using following command to moving the single item fro one folder to another folder. But it is only copy the folder not the source folder structure. I want that file should be the folder structure. For example

    Source folder - c:\temp\info\2017
    Source File Name - MyInfo.doc

    Target Folder - c:\myinfo\finance

    File should be copy as c:\myinfo\finance\info\2017\MyInfo.doc

    Move-Item $oldPath -Destination $newFullPath -ErrorAction Stop -Force

    Please advise

    Tuesday, June 6, 2017 1:05 PM

All replies

  • If you like to have a part of the source folder structure as the destination folder structure you will have to create this destination folder structure first. Robocopy is able to copy empty folder structures - this might help you a little bit.

    Grüße - Best regards

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


    • Edited by BOfH-666 Tuesday, June 6, 2017 1:15 PM
    • Proposed as answer by jrv Tuesday, June 6, 2017 6:14 PM
    Tuesday, June 6, 2017 1:14 PM
  • You can also extract the folder path from the source and add it to the destination path.

     

    \_(ツ)_/

    • Proposed as answer by Hello_2018 Wednesday, June 7, 2017 10:06 AM
    Tuesday, June 6, 2017 6:24 PM
  • Hi,

    Besides of others suggestion, i suppose you could make your script more graceful:

    function do-something
    {
        cd  c:\temp\
        [void][system.reflection.assembly]::LoadWithPartialName('microsoft.visualbasic')
        #[cmdletbinding()]
     
            #[parameter(Mandatory=$true,HelpMessage='Need path')]
         [string]$path = [Microsoft.VisualBasic.Interaction]::inputbox('Pls enter afile path','File Path','info\2017')
        
    
        try{
           Microsoft.PowerShell.Management\Move-Item -Path $path -Destination c:\myinfo\finance\ -ErrorAction Stop
    
        }catch{
            $_.exception.message
        }
    }
    do-something

    Change something to suit your needs.

    Best regards,

    Andy


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    • Proposed as answer by Hello_2018 Thursday, June 22, 2017 6:59 AM
    Wednesday, June 7, 2017 10:06 AM
  • Hi ,

    did this issue was resolved?

    if not please share the current situation for further assistance.

    Best regards,

    Andy


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Tuesday, June 13, 2017 3:02 AM