Copy folders and subfolders only

I am looking for a method to copy the entire folder structure(only) from one network drive to another.  I do not want any files copied, just the folders and subfolders.  

If there is a program that can do this effectively, I am open to that.

Some of these folders may have subfolders levels that go 5-6 levels deep.

Thanks for any suggestions?
snyperjAsked:
Who is Participating?
 
Shaun VermaakConnect With a Mentor Technical Specialist/DeveloperCommented:
robocopy c:\Folder1 c:\Folder2 /e /xf *

Open in new window

0
 
Bill PrewCommented:
XCOPY /T /E can do that for you, as in:

XCOPY x:\fromdir y:\todir /T /E

You can see other options by doing:

XCOPY /?


»bp
0
 
snyperjAuthor Commented:
Thanks
0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
Jose Gabriel Ortega CCEO J0rt3g4 Consulting ServicesCommented:
And the powershell form:

$source="D:\Cloud\OneDrive - J0rt3g4 Consulting Services\Odesk"
$target="f:\test"

Get-ChildItem -Path $source -Recurse -Directory | %{ [System.IO.Directory]::CreateDirectory("$target$($_.FullName.Replace($source,""""))") }

Open in new window

0
 
Jose Gabriel Ortega CCEO J0rt3g4 Consulting ServicesCommented:
Bill, you need to change the $source and $target.
I did run the script again and it worked like a charm.
I'm using powershell v5.

$source="D:\Cloud\OneDrive - J0rt3g4 Consulting Services\AllFotosHistorical"
$target="f:\test"

Get-ChildItem -Path $source -Recurse -Directory | %{ 
	[System.IO.Directory]::CreateDirectory("$target$($_.FullName.Replace($source,""""))") 
}

Open in new window


xx.png
Even from this question I made a script on technet.

https://gallery.technet.microsoft.com/scriptcenter/Create-Folders-structure-6bb190c5?redir=0
0
 
Bill PrewCommented:
Jose,

My version:

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      16299  98     

Open in new window


I had changed the variables used in your script, as follows.  Both these folders exist, the first has a number of subfolders, the other is empty.  Still no love here, I just get errors when I run your original script.  If you say it works for you I believe you, but it doesn't go so well here...

sshot-422.png

»bp
0
 
Jose Gabriel Ortega CCEO J0rt3g4 Consulting ServicesCommented:
Ok Bill,
Try this,
$source="D:\Cloud\OneDrive - J0rt3g4 Consulting Services\AllFotosHistorical"
$target="f:\test"

Get-ChildItem -Path $source -Recurse -Directory | %{ 
    $tmp = "$target$($_.FullName.Replace($source,""""))"
    Write-host "Creating Folder ""$tmp""" -ForegroundColor Gray
	[System.IO.Directory]::CreateDirectory($tmp)  | Out-Null
}

Open in new window


Let's see how is that $tmp var going for with you
We are in same version
Name                           Value                                                                                                                      
----                           -----                                                                                                                      
PSVersion                      5.1.16299.98
0
 
Bill PrewCommented:
PS C:\Users\bprew> $source="c:\temp"
$target="\\ds\bill\ee\temp3"
Get-ChildItem -Path $source -Recurse -Directory | %{ 
    $tmp = "$target$($_.FullName.Replace($source,""""))"
    Write-host "Creating Folder ""$tmp""" -ForegroundColor Gray
	[System.IO.Directory]::CreateDirectory($tmp)  | Out-Null
}
Creating Folder "\\ds\bill\ee\temp3C:\temp\.vs"
Exception calling "CreateDirectory" with "1" argument(s): "The given path's format is not supported."
At line:6 char:2
+     [System.IO.Directory]::CreateDirectory($tmp)  | Out-Null
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : NotSupportedException
 
Creating Folder "\\ds\bill\ee\temp3C:\temp\bb2"
Exception calling "CreateDirectory" with "1" argument(s): "The given path's format is not supported."
At line:6 char:2
+     [System.IO.Directory]::CreateDirectory($tmp)  | Out-Null
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : NotSupportedException

Open in new window


»bp
0
 
Bill PrewCommented:
Looks like a bug, concatenating the full path instead of relative?

Creating Folder "\\ds\bill\ee\temp3C:\temp\.vs"

Open in new window


»bp
0
 
Jose Gabriel Ortega CCEO J0rt3g4 Consulting ServicesCommented:
Yeah, also I got errors when the target is a network address.
I will fix that later ..
It's nice to have other people to test your code.

Ty bill.

tried this (and worked):
$source="D:\Cloud\OneDrive - J0rt3g4 Consulting Services\AllFotosHistorical"
$target="\\172.16.16.10\public\te"

Get-ChildItem -Path $source -Recurse -Directory | %{ 
    $tmp = "$target$($_.FullName.Replace($source,""""))"
    Write-host "Creating Folder ""$tmp""" -ForegroundColor Gray
    if(Test-Path $tmp){
        New-Item -ItemType Directory -Path "$tmp" | Out-Null
        #[System.IO.Directory]::CreateDirectory($tmp)  | Out-Null
    }
}

Open in new window


still needs to get exception managed but whatever :) will look at later.
1
 
Bill PrewCommented:
Welcome, wasn't trying to exclude your answer, I like the variety of various approaches.  So I decided to test them all expecting all to work before I recommended a close.  Glad something useful came of that, keep up the good work!


»bp
1
 
Jose Gabriel Ortega CCEO J0rt3g4 Consulting ServicesCommented:
Could you please try to test this?
https://gallery.technet.microsoft.com/scriptcenter/Create-Folders-structure-6bb190c5?redir=0

hopefully it will work.

Jose
0
 
Bill PrewCommented:
Jose,

No luck with that either.


»bp
1
 
Bill PrewCommented:
I'll stand by my original recomendation in #a42463053.


»bp
0
 
snyperjAuthor Commented:
sorry for the delay.  Robocopy is what I did use.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.