Question
· Jan 15, 2020

Gzipping several files individually and renaming using datetimestamp

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

Discussion (2)0
Log in or sign up to continue

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)
}

}