copy - How I can compare and move data from A to B in Powershell older than x Days? -


i have problem powershell script. ;( want delete/ move/ compare powershell.

here idea:

if start script remove empty folder a. after want move data b x days older. (here first problem)

if make copy works fine.

a other idea compare , b , diffrend copy or move. (but don't know how can this)

here code:

function removefiles($source,$destination){     $elements = get-childitem $source -recurse     foreach($element in $elements){         if(($element.psiscontainer) -and (!(get-childitem -recurse -path $element.fullname))){             write-host "delete: " $element.fullname             remove-item $element.fullname -confirm:$false         }     } }  function copyfiles($source,$destination,$days){     $elements = get-childitem $source -recurse     $lastwrite = (get-date).adddays(-$days)     foreach($element in $elements){         if($element.creationtime -le $lastwrite){             $targetfile = $destination + $element.fullname.substring($source.length)             if($element.psiscontainer){                 write-host "copy folder : " $element.fullname                 copy-item $element.fullname -destination $targetfile             }else{                 write-host "copy file : " $element.fullname                 copy-item $element.fullname -destination $targetfile             }         }     } }  function movefiles($source,$destination,$days){    get-childitem -path $source -recurse | where-object {$_.lastwritetime -lt (get-date).adddays(-2)} | move-item -destination $destination }  cls  $source = "c:\users\tarasov_w\downloads" $destination = "c:\users\tarasov_w\desktop\ps_test" $logfile = "c:\users\tarasov_w\desktop\$(get-date -format 'mmddyyyy').txt"  $days = 1  start-transcript $logfile -noclobber  write-host "start..."  removefiles -source $source -destination $destination  #copyfiles -source $source -destination $destination -days $days  movefiles -source $source -destination $destination -days $days  write-host "fertig!" 

update:

function comparefiles($source,$destination){     $foldera = get-childitem $source -recurse     $folderb = get-childitem $destination -recurse      $diff = compare-object -referenceobject $foldera -differenceobject $folderb -passthru      foreach($element in $diff){         $element_fullname = $element.fullname           if($element.psiscontainer){            # ????         }      } } 


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -