I'm trying to move a directory structure from one folder to another using Robocopy, and I want to skip the first level of folders. Here's what my current directory looks like:
* a
* aa
* aaa.txt
* aa.txt
* aaa
* b
* bb
* bbb.txt
* bb.txt
* bbb
* c
* cc.txt
After the move, I want it to look like this:
* completelyDifferentFolder
* aa
* aaa.txt
* aa.txt
* aaa
* bb
* bbb.txt
* bb.txt
* bbb
* cc.txt
I've been trying to figure out how to do this. I have attempted using `robocopy %source% %target% ** /E /xf meta.ini`, but it didn't work. I also tried a PowerShell script but faced issues with the `gci` command not being recognized. Does anyone know how I can achieve this?
4 Answers
If this is a one-time copy, just use PowerShell. You can try this:
`Get-ChildItem -Path "D:Source" -Directory | ForEach-Object {
Copy-Item -Path "$_*" -Exclude "meta.ini" -Destination "D:destinationfolder" -Recurse -Force}`
This will copy all files and folders in the first-level directories without the `meta.ini` file. For Robocopy users, here's an alternative:
`Get-ChildItem -Path "D:source" -Directory | ForEach-Object {
$sourcePath = "D:source$_"
$destinationPath = "D:DestinationFolder"
robocopy $sourcePath $destinationPath /E /xf "meta.ini"
}`
You can try a command like this for Robocopy:
`For /d %a in (srcroot?) do RoboCopy /mov %a dstroot`
This should work, but make sure you test it first to confirm it does what you expect.
Just a heads up, that command might not do exactly what you're aiming for—it could copy more than just from the second level, and it may not exclude the `meta.ini` file either. Just double-check before running it!
What if my PowerShell isn't recognizing the Get-ChildItem command? I'm on Windows 10 with the latest updates installed.
It sounds like your PowerShell might have some config issues, or you might not be running a proper PowerShell session. Make sure you're using Windows PowerShell or PowerShell Core, and try running it as an administrator.