Skip to content

Instantly share code, notes, and snippets.

@cjfarrelly
Created October 14, 2014 15:39
Show Gist options
  • Save cjfarrelly/95a278a8d66a101a9019 to your computer and use it in GitHub Desktop.
Save cjfarrelly/95a278a8d66a101a9019 to your computer and use it in GitHub Desktop.
The gist below will copy all html files from one directory to another keeping the directory structure in place
function Create-WebSite
{
Push-Location ..\
$webSiteContainer = "WebSite"
Remove-Item .\$webSiteContainer -Recurse -Force
New-Item -ItemType "directory" -Name $webSiteContainer | Out-Null
$items = Get-ChildItem -Recurse -Filter "*.html"
foreach ($item in $items)
{
$itemRelativePath = $item | Resolve-Path -Relative
$itemRelativePath = $itemRelativePath.Remove(0,2)
$containingFolder = Join-Path $webSiteContainer $itemRelativePath.Replace($item.Name , "")
if(!(Test-Path $containingFolder))
{
New-Item -ItemType "directory" -Name $containingFolder | Out-Null
}
Move-Item -Path $item.FullName -Destination $containingFolder -Force
}
Pop-Location
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment