title: Need a bach script to archive old files by zipping
body: <p>I am new to Batch scripting so expecting the help of the professionals.</p>
  
  <p>I have <code>E:\TIBCO\Spotfire Web Player\6.0.0\Logfiles with Spotfire.Dxp.Web.*.*</code> files and<br>
         <code>E:\TIBCO\Automation Services\6.0.0\LogFiles with Spotfire.Dxp.Automation.*.*</code> files</p>
  
  <p>and I need to</p>
  
  <pre><code>1. move (copy &amp; delete) all the files that are with Spotfire.Dxp.*.*.* (ex Spotfire.Dxp.*.1.*)  from the above paths to E:\TIBCO\logsArchival\rotatedDir 
  2. zip all the files that are older than 60 from E:\TIBCO\logsArchival\rotatedDir to E:\TIBCO\logsArchival\ArchiveDir
  3. delete the zip files that are older than 120 days from E:\TIBCO\logsArchival\ArchiveDir
  
  all the above steps need to be written to the logs.
  </code></pre>
  
  <p>i have a powershell script which is working from command prompt but not working when called from a scheduler agent called SafTT. The logic needs to be written in batch script.</p>
  
  <pre><code>     $sysname=$env:COMPUTERNAME
       $Date = Get-Date
       $Now = Get-Date -format yyyy-MM-dd-HH-mm-ss
       $host_date=$sysname +"_"+ $Now
  
       $RotateDays = "60"
       $ArchiveDays="120"
       $ProjectLogsDir = "E:\TIBCO\*\6.0.0\Logfiles"
       $RotatedLogsDir = "E:\TIBCO\logsArchival\rotatedDir"
       $ArchivedLogsDir= "E:\TIBCO\logsArchival\archiveDir"
       $psLogsDir= "E:\TIBCO\logsArchival\shLogsDir"
  
       $LastRotate = $Date.AddDays(-$RotateDays)
       $LastArchive = $Date.AddDays(-$ArchiveDays)
  
       $RenameLogFiles = Get-Childitem $ProjectLogsDir -include Spotfire.Dxp.*.*.* -exclude spotfire.Dxp.web.KeepAlive.* -Recurse
       $RenameLogFiles
       $RenameLogFiles | Where-Object {!$_.PSIsContainer} |  Rename-Item -NewName { $host_date +"_"+ $_.Name.Replace(' ','_') };
  
       $RotatedLogFiles = Get-Childitem $ProjectLogsDir -include *_Spotfire.Dxp.*.*.* -Recurse
       $RotatedLogFiles
       $RotatedLogFiles | move-item -destination "$RotatedLogsDir"
  
       $ZippedLogFiles = Get-Childitem $RotatedLogsDir -include *_Spotfire.Dxp.*.*.* -Recurse | Where {$_.LastWriteTime -le "$LastRotate"}
       $ZippedLogFiles
     Zip $ArchivedLogsDir\$host_date.zip -j $ZippedLogFiles
       $ZippedLogFiles | Remove-Item -Force
  
       $DeleteZippedFiles = Get-Childitem $ArchivedLogsDir\*.zip -Recurse | Where {$_.LastWriteTime -le "$LastArchive"}
       $DeleteZippedFiles
       $DeleteZippedFiles | Remove-Item -Force
  
       $DeletePsFiles = Get-Childitem $psLogsDir\*.log -Recurse | Where {$_.LastWriteTime -le "$LastRotate"}
       $DeletePsFiles
       $DeletePsFiles | Remove-Item -Force
  </code></pre>