Copy folder structure and files
hello, have piece of code below working still need requirements below met:
- folder structure of archive destination needs match source destination. new folders added archive (never deleted)- new logfile created each job
- logging showing step process in needs included (output text file). please see below example:
job date : current date (this being shown once each job run)
-----------------------------------------------------------------------------------------
opration id : sequential number (reset 1 @ every new job run)
operation type : create or move ( true when dealing folder(s) or file(s))
object type : folder or file
object name : name of file or folder being processed
start time : starting time of current operation
end time : completion time of current operation
code below:
$log $spath = "sourcepath" $archivepath = "destinationpath" $max_days = "-65" #max_mins = "-5" $curr_date = get-date $thresholddate = $curr_date.adddays($max_days) "source path : $spath" "archive path : $archivepath" "archive threashold: thresholddate" #checking date , copying file sourcepath archivepath foreach($file in (get-childitem $spath -recurse)) { if($file.lastwritetime -gt ($curr_date).adddays($max_days)) { $writedate = $file.lastwritetime "keeping / not archiving $file last write time $writedate" } else { "archiving file: $file" new-item -itemtype directory -force -path $archivepath #copy-item -path $file.fullname -destination $archivepath move-item -path $file.fullname -destination $archivepath } }
thanks helping this.
this robocopy used for. of in 1 line detailed logging.
change topic "discussion" "question"
\_(ツ)_/
Windows Server > Windows PowerShell
Comments
Post a Comment