header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Copy-item won't create subfolders
Last Post 26 Jun 2010 08:06 AM by Jay. 8 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Not Resolved
JayUser is Offline
New Member
New Member
Posts:15
Avatar

--
26 Jun 2010 05:56 AM
    Hi All,
    I'm trying to copy a folder structure and it works with my 1st command but not the 2nd.
    gc c:\!Demo\list.txt|%{Copy-Item -Path $_ -Destination ($_ -replace "C:\\!Demo\\", "C:\!Demo\Test\")}
    gc c:\AD\list.txt |%{Copy-Item -Path $_ -Destination ($_ -replace "C:\\AD\\","C:\AD\Test\")}

    Unless I've been looking at this to long these 2 lines should work the same:( 1st one does but 2nd one doesn't
    I get the following error for each file when trying the 2nd line above.
    Copy-Item : Could not find a part of the path 'C:\AD\Test\2007.txt'. At line:1 char:31 + gc c:\AD\list.txt|%{Copy-Item <<<< -Path $_ -Destination ($_ -replace "C:\\AD\\","C:\AD\Test\")} + CategoryInfo : NotSpecified: (:) [Copy-Item], DirectoryNotFoundException + FullyQualifiedErrorId : System.IO.DirectoryNotFoundException,Microsoft.PowerShell.Commands.CopyItemCommand

    Thanks for any help on this one.
    Jay
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    26 Jun 2010 06:03 AM
    You want to copy just the folder structure, not files, correct?

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    JayUser is Offline
    New Member
    New Member
    Posts:15
    Avatar

    --
    26 Jun 2010 06:38 AM

    Hi Shay,

    Actually I want to copy both. I found if I create subfolders separately then my files will copy fine. But if subfolder not there then get error messages. Can't figure out why my 1st line works just fine and 2nd doesn't. Folder properties and permissions are the same. I guess I could make 2 passes if you know how to get folders created and then I could copy files. I'm on a very tight time frame right now so just need it to work.

    Thanks,

    Jay

    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    26 Jun 2010 06:42 AM
    This works for me ( D:\ScriptsBackup doesn't exist and gets created):

    Copy-Item D:\Scripts -Recurse -Destination D:\ScriptsBackup

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    JayUser is Offline
    New Member
    New Member
    Posts:15
    Avatar

    --
    26 Jun 2010 06:54 AM
    That's what I don't get. I think both of my commands are basically doing what you did except the 1st one works and 2nd doesn't. Any other ideas? I don't get it:(
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    26 Jun 2010 07:05 AM
    Can you try this:

    gc c:\AD\list.txt |% {
    Copy-Item -Path $_ -Destination ($_.substring(0,6)+"test\"+$_.substring(6))
    }

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    JayUser is Offline
    New Member
    New Member
    Posts:15
    Avatar

    --
    26 Jun 2010 07:42 AM
    Unfortunately same result
    Copy-Item : Could not find a part of the path 'C:\AD\test\2007.txt'.
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    26 Jun 2010 07:44 AM
    My bad, add -Force -Recurse to copy-item.

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    JayUser is Offline
    New Member
    New Member
    Posts:15
    Avatar

    --
    26 Jun 2010 08:06 AM
    I had tried that before with same result. I don't use the recurse becuase the list.txt is actually a list of files in AD folder. This is just a simple test of what I need to do in production. In production I'm actually needing to remove 1600+ files from a list that I've been given.
    The files are scattered throughout many subdirectories. I could probably get them out by hard coding a destination but want to try and preserve folder structure so it will be easy to put files back into original structure when needed. Hope that makes sense. So my copy-item really will become a move-item but for getting past this problem found it easier to use copy-item
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer