SHARE
TWEET

Duplicate File Structure With Empty Files

a guest Jul 14th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $SourceRoot = "Z:\foo"
  2. $DestRoot = "Z:\bar"
  3. $SourceContent = Get-ChildItem $SourceRoot -Recurse
  4.  
  5. # Populate the destination with files and sub-folders.
  6. $SourceContent | ForEach-Object {
  7.     If ($_.PSIsContainer) {$NewItemType = "Directory"}
  8.     Else {$NewItemType = "File"}
  9.    
  10.     $newitem = ($_.fullname).replace($SourceRoot, $DestRoot)
  11.     New-Item -Path $newitem -ItemType $NewItemType -force
  12. }
  13.  
  14. # Duplicate the source item timestamps.
  15. # When a file is written to a folder, it causes the folder's 'LastWriteTime' to
  16. # be updated. This is why we don't set the timestamps while populating the
  17. # destination with files and sub-folders.
  18. $SourceContent | ForEach-Object {
  19.     $newitem = ($_.fullname).replace($SourceRoot, $DestRoot)
  20.     (Get-Item -Path $newitem).LastWriteTime = $_.LastWriteTime
  21.     (Get-Item -Path $newitem).CreationTime = $_.CreationTime
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top