Skip to content

Instantly share code, notes, and snippets.

@HaydenElza
Created January 15, 2025 21:20
Show Gist options
  • Save HaydenElza/1817562b8671b98189286580c8f3aa11 to your computer and use it in GitHub Desktop.
Save HaydenElza/1817562b8671b98189286580c8f3aa11 to your computer and use it in GitHub Desktop.
Power shell script to copy only the first level folders of a directory, no files or subfolders.
# Source and destination paths
$sourcePath = "C:\source"
$destinationPath = "C:\destination"
# Get only the top-level folders
$folders = Get-ChildItem -Path $sourcePath -Directory
# Copy each folder
foreach ($folder in $folders) {
Copy-Item -Path $folder.FullName -Destination $destinationPath -Container
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment