File Mover Blog

March 24, 2022

Move txt files if the line count is more than one

Q: I am looking to move txt files to a location. If the line count is more than 1 (more than just a header) move to processing.
A: Yes this is possible using some Pascal Script.

1. Be sure that you will only handle text files. We’ve added a File Name Include Filter:

Limagito File Mover Filename Filter

2.Please open the ‘Pascal Script’ option:

Limagito File Mover Pascal Script option

3. Enable and Add the following ‘On Destination’ Pascal Script. You can choose between 0 or -1 as result for psExitCode var. 0 will give an error when such a file is found, -1 will skip such a file.

Var
  tmpFile: String;
  tmpList: TStringList;
Begin
  psExitCode:= 1;
  // ... add your code here
  tmpFile := psFilePath + psFileName;
  tmpList := TStringList.Create;
  Try
    Try
      tmpList.LoadFromFile(tmpFile);
      If tmpList.Count < 2 Then
      Begin
        // Invalid count
        psExitcode := -1; // := -1 is Skip File and := 0 is Error on File
        psLogWrite(1, '', 'Invalid recordcount in ' + tmpfile);      
      End;  
    Except
      // Error
      psExitCode := 0;
      psLogWrite(1, '', 'Error loading ' + tmpfile);
    End;
  Finally
    tmpList.Free;
  End;  
End.

Limagito File Mover Line Count is more

4. RunTime Log

Limagito File Mover RunTime Log

#Filetransfer

If you need any info about this ‘line count is more than’ request, please let us know.

Best regards,

Limagito Team

By Limagito Pascal Script Share: