I am trying to copy only the folders that are within a directory, the script provided in the answer to this question copies all content within the directory: How can i only copy folders with robocopy in powershell?
The code from this answer is provided below:
Get-ChildItem 'C:\temp\test' |
ForEach-Object {
$newname = ($_.BaseName -Replace '[^\x20-\x5D,\x60-\x7E]+', '-')
if (($_.GetType()).Name -eq "DirectoryInfo"){
write-host "folder"
}
write-host $_.BaseName
write-host $newname
robocopy.exe "C:\temp\test\$($_.BaseName)" "C:\temp\test\copy\$newname"
}
robocopy /CREATE, orxcopy /T?/CREATEoption ofrobocopy(which is likely unsuitable since it also creates zero-length files), or at thexcopycommand and its/Toption (maybe together with/E), which is intended to create the destination directory tree without copying any files...