Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $SourceRoot = "Z:\foo"
- $DestRoot = "Z:\bar"
- $SourceContent = Get-ChildItem $SourceRoot -Recurse
- # Populate the destination with files and sub-folders.
- $SourceContent | ForEach-Object {
- If ($_.PSIsContainer) {$NewItemType = "Directory"}
- Else {$NewItemType = "File"}
- $newitem = ($_.fullname).replace($SourceRoot, $DestRoot)
- New-Item -Path $newitem -ItemType $NewItemType -force
- }
- # Duplicate the source item timestamps.
- # When a file is written to a folder, it causes the folder's 'LastWriteTime' to
- # be updated. This is why we don't set the timestamps while populating the
- # destination with files and sub-folders.
- $SourceContent | ForEach-Object {
- $newitem = ($_.fullname).replace($SourceRoot, $DestRoot)
- (Get-Item -Path $newitem).LastWriteTime = $_.LastWriteTime
- (Get-Item -Path $newitem).CreationTime = $_.CreationTime
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement