Gzipping several files individually and renaming using datetimestamp

Primary tabs

HealthShare

I currently have a batch job that performs many functions. Two of them are below. I was wondering how this can be done in a custom class 

      mv $TEMPDIR/$FILE   $TEMPDIR/$FILEa"_$DATESTAMP.txt" 
     mv $TEMPDIR/$FILE1  $TEMPDIR/$FILE1a"_$DATESTAMP.txt" 
     mv $TEMPDIR/$FILE2  $TEMPDIR/$FILE2a"_$DATESTAMP.txt" 
     mv $TEMPDIR/$FILE3  $TEMPDIR/$FILE3a"_$DATESTAMP.txt"
     mv $TEMPDIR/$FILE4  $TEMPDIR/$FILE4a"_$DATESTAMP.txt" 
    #Gzip files 
    find $TEMPDIR -type f ! -iname '*gz' -exec gzip '{}' \; 

 

Thank you

Replies

Example with one file for Windows:

Class dc.test Abstract ]
{

/// d ##class(dc.test).test()
ClassMethod test()
{
  ts=##class(%PosixTime).LogicalToUnixTime(##class(%PosixTime).CurrentUTCTimeStamp()),
    oldName="C:\Tmp\test",
    newName=oldName_$$$FormatText("a%1.txt",ts)
  
  f=##class(%Stream.FileBinary).%New()
  f.LinkToFile(oldName)
  
  gz=##class(%Stream.FileBinaryGzip).%New()
  gz.Filename=newName
  gz.CopyFromAndSave(f)

  ##class(%File).Delete(oldName)
}

}

Hi,

Thanks so much for the quick response. We are actually on Suse Linux and there are multiple(5) files.

Thank you

Lou