• 26 May

    Get a field value to rename a csv file

    Q: Get a field value to rename a file. I received a file with a specific filename every week which goes through various processes, after I have finished I need to send the original data with some extra data columns generated by our process back to the client using the original filename. Unfortunately, I cannot keep hold of the filename throughout the process but I can have a column in the return file which contains the original filename. Is there a way I can use Filmover to have a look at a specific column of a data file get the contents of it and use it to rename the file to that value then deleted the column that I got the information from? Bit complex but I thought I’d ask before exploring other avenues. The column that contains the original filename to be used and then deleted is called IMPNAME.

    A: Should be possible (we received an example file of the customer).

    • Please set filename filter to *.csv

    limagito file mover filename filter

    • Add ‘Pascal Script’ as Destination:

    limagito file mover pascal script as destination

    • Don’t forget to adjust the ctOutputPath Const (must end with a \ )
    Var
      iEntry, iIndex, iList: Integer;
      tmpFilename, tmpInputFile, tmpOutputFile: String;
      tmpEntryList, tmpFileList: TStringList;
    Const
      ctOutputPath = 'C:\Test\Out_Csv\';  // Must end with a \
      ctIMPNAME = 'IMPNAME';
    Begin
      psExitCode := 0;
      iIndex := -1;
      tmpInputFile := psFilePath + psFilename;
      tmpOutputFile := '';
      // ... add your code here
      tmpEntryList := TStringList.Create;
      tmpEntryList.Delimiter := ',';
      tmpEntryList.StrictDelimiter := True;
      tmpEntryList.QuoteChar := '"';
      tmpFileList := TStringList.Create;
      Try
        Try
          tmpFileList.LoadFromFile(tmpInputFile);
          tmpEntryList.DelimitedText := tmpFileList.Strings[0];
          For iEntry := 0 to (tmpEntryList.Count - 1) Do
          Begin
            If SameText(ctIMPNAME, tmpEntryList.Strings[iEntry]) Then
            Begin
              iIndex := iEntry;
              psLogWrite(1, '', 'Found ' + ctIMPNAME + ' at Column with Index ' + IntToStr(iIndex));
              Break;
            End;
          End;
          // Did we find 'IMPNAME'
          If iIndex <> -1 Then
          Begin
            tmpFileList.Strings[0] := psStringReplace(tmpFileList.Strings[0], ',"' + ctIMPNAME + '"', '');
            For iList := 1 to (tmpFileList.Count - 1) Do
            Begin
              tmpEntryList.DelimitedText := tmpFileList.Strings[iList];
              If tmpEntryList.Count > iIndex Then
              Begin
                If tmpOutputFile = '' Then
                Begin
                  tmpFilename := tmpEntryList.Strings[iIndex];
                  If tmpFilename <> '' Then
                    tmpOutputFile := ctOutputPath + tmpFilename + '.csv';
                End;  
                If tmpFilename <> '' Then
                Begin
                  tmpFileList.Strings[iList] := psStringReplace(tmpFileList.Strings[iList], ',"' + tmpFileName + '"', '');           
                  psLogWrite(1, '', 'Entry: ' + tmpOutputFile + ' : ' + tmpFileList.Strings[iList]);
                End;  
              End;
            End;
          End;
          // Save To File
          If tmpOutputFile <> '' Then
          Begin
            Try
              tmpFileList.saveToFile(tmpOutputFile);
              psExitCode := 1;
            Except
              psLogWrite(1, '', 'Error saving file: ' + tmpOutputFile);
            End;
          End;
        Except
          psLogWrite(1, '', 'Error loading file: ' + tmpInputFile);
        End;
      Finally
        tmpEntryList.Free;
        tmpFileList.Free;
      End;
    End.

    Get a field value

     

    #filetransfer #mft #filemanagement #csv

    If you need any info  about this ‘get a field value to rename a file’, please let us know.

    Best regards,

    Limagito Team

    By Limagito-Team CSV ,
  • 26 May

    Image and sidecar xml workflow question

    Q: We have a new process that backs up and then moves an image file and sidecar xml file into an input directory [folder A] for our automated photo toning software.
    The xml file contains instructions for cropping and has the same name as the image file with the exception of their file extensions, for example 230519_511627666.xml and 230519_511627666.jpg.
    The photo toning software ingests both the .xml and .jpg and attempts to tone the image, but if the .jpg fails it is output to an error folder [B] without being cropped and toned.
    We pick up the errored .jpg from folder B, resize it with other software and drop it to another folder [C].
    We need to then move the .jpg from folder C back to input folder A to try it again, but it requires its corresponding .xml file which can be found in the backup folder [D] be dropped alongside it again to process and tone.
    Is it possible with a Limagito rule to monitor source folder C and if an image file is found, grab the .xml file of the same name from folder D, then drop them both to folder A?
    Hope that makes sense! Thanks, David

    A: Yes, should be possible. We’ll prepare a script for this asap.

    • We created the following directory structure for the test of the script:

    Image and sidecar xml

    • Source is the C folder (resized files):

    Limagito file mover windows as source

    • Filename Include Filter, we only want to scan for jpg files:

    limagito file mover filename include filter

    • Enable and add ‘On Destination’ Pascal Script:

    limagito file mover pascal script

    • Don’t forget to adjust the Path const values:
    var
      tmpFilename: String;
    Const
      // Path must end with a \
      ctBackupPath = 'C:\Test\AJC\D\';
      ctDestinationPath = 'C:\Test\AJC\A\';
    Begin
      psExitCode:= 0;
      tmpFilename := ChangeFileExt(psFileName, '.xml');
      If FileExists(ctBackupPath + tmpFilename) Then
      Begin
        If psCopyFile(ctBackupPath + tmpFilename, ctDestinationPath + tmpFilename, False) Then
        Begin
           psExitCode:= 1;
           psLogWrite(1, '', 'Copy file success of ' + ctBackupPath + tmpFilename + ' to ' + ctDestinationPath + tmpFilename);
        End
        Else
        Begin
          psLogWrite(1, '', 'Copy file error of ' + ctBackupPath + tmpFilename + ' to ' + ctDestinationPath + tmpFilename);
        End;
      End
      Else
        psLogWrite(1, '', 'Error, xml file does not exist: ' + ctBackupPath + tmpFilename);
    End.

    limagito file mover pascal script as destination

    Feedback user:

    • Thank you, I’ll try this out and let you know if I have any issues with it. Appreciate the quick response!
    • Just wanted to update, this rule and script appears to work great and I have it in place in our production workflow now, thanks again!

    #filetransfer #mft #filemanagement

    If you need any info  about this ‘Image and sidecar xml workflow question’, please let us know.

    Best regards,

    Limagito Team

     

    By Limagito-Team Image Pascal Script , ,
  • 14 May

    New counters added in Limagito File Mover

    Newly added in Limagito File Mover recently:

    Values total counters (history):

    • psTotalFiles Counter:  %CSC
    • psTotalFilesSrcError Counter:  %CFS
    • psTotalFileDstError Counter:  %CFD
    • psTotalControlSrc Counter:  %CCS
    • psTotalControlDst Counter:  %CCD

    The following counters will reset themself On Rule Begin:

    • psCurrentsFiles Counter:  %ZSC
    • psCurrentFilesSrcError Counter:  %ZFS
    • psCurrentFilesDstError Counter:  %ZFD
    • psCurrentControlSrcError Counter:  %ZCS
    • psCurrentControlDstError Counter:  %ZCD

    limagito file mover counter parameters

    These can be used for example in email events.

    New counters added and used in email events

     

    Result of sent email:

    New counters added in email example

    These counters are also available as Pascal Script var so this means you can control only to send an error email if for example the value of an error counter reaches a certain value.

    limagito file mover on error event

    Important, enable ‘Use Pascal Script as Event Precondition’ in the options tab:

    use pascal script as precondition in limagito file mover

    You can create any combination of our counters to determine when the error event should actually be sent. Please let us know if you need any help here.

    limagito file mover pascal script as precondition using counters

    An example of the the new counters being used in our Pascal Script ‘On Rule End’ option:

    New counters added in our file mover pascal script option

    RunTime Log Result:

    New counters added in our file mover pascal script option

    #filetransfer #mft #filemanagement

    If you need any info  please let us know.

    Best regards,

    Limagito Team

    By Limagito-Team How-to Pascal Script
SEARCH