Pascal Script

  • 07 May

    Q&A 43: Read first line of a file and move to a specific folder

    Q: Read first line of a file and move to a specific folder. I have some files that sit on a server and I would like to move them off to archive. Each file has a code in the first line that tells me where the file came from. The files are regular text (.txt) files. How can I set up Limagito to move the file based on that code? If the code contains B01, move to a folder named Branch1. If the code contains B02, move to a folder named Branch2. The code will usually have more letters surrounding the B01 and B02, so I need the logic to pick up on B01 and B02 being in the code.
    A: Yes this is possible. All you need a simple Pascal Script. We’ve added some screenshots to get you started.

    As a start we added a new Moving Rule with WIN as Source. In the windows source folder we added some txt files. We’ll read the first line and check if certain codes exists (B01, B02, ..). Depending on the code found we’ll use a different subfolder of the Destination folder. If this subfolder doesn’t exist then we’ll create it.

    1.Please open the Pascal Script option:

    LimagitoX File Mover Pascal Script

    2. Enable and add the following ‘On Destination’ Pascal Script:

    var
      tmpLine: String;
      tmpList: TStringList;
    Begin
      psExitCode:= 0;
      psVSA := 'Unknown'
      // ... add your code here
      tmpList := TStringList.Create;
      Try
        try
          tmpList.LoadFromFile(psFilePath + psFileName);
          // Check First Line
          If tmpList.Count <> 0 Then
          Begin
            tmpLine := UpperCase(tmpList.Strings[0]);
            psLogWrite(1, '', 'First Line: ' + tmpLine);
            // check
            If Pos('B01', tmpLine) <> 0 Then psVSA := 'Alabama';
            If Pos('B02', tmpLine) <> 0 Then psVSA := 'Alaska';
            If Pos('B03', tmpLine) <> 0 Then psVSA := 'Arizona';
            If Pos('B04', tmpLine) <> 0 Then psVSA := 'Arkansas';
            If Pos('B05', tmpLine) <> 0 Then psVSA := 'California';
            If Pos('B06', tmpLine) <> 0 Then psVSA := 'Colorado';
            If Pos('B07', tmpLine) <> 0 Then psVSA := 'Connecticut';
            If Pos('B08', tmpLine) <> 0 Then psVSA := 'Delaware';
            If Pos('B09', tmpLine) <> 0 Then psVSA := 'Florida';
            If Pos('B10', tmpLine) <> 0 Then psVSA := 'Georgia';
            // Set ExitCode
            psLogWrite(1, '', 'Subfolder which will be used ' + psVSA);
            psExitCode := 1;
          End
          Else
            psLogWrite(1, '', 'Error no lines in ' + psFilePath + psFileName);
        Except
          psLogWrite(1, '', 'Error when loading ' + psFilePath + psFileName);
        End;
      Finally
        tmpList.Free;
      End;
    End.

    Limagito File Mover Pascal Script On Destination

    3. Destination Setup, Create Subdir, option:  %VSA

    XFM Limagito File Mover Destination SubDir option

    4. RunTime Log Result

    Limagito File Mover RunTime Log

    5. Destination SubFolder Structure, if subfolder doesn’t exist then it will be create by our File Mover:

    #FileTransfer

    If you need any help with this ‘Read first line of a file’ request, please let us know.

    Happy Easter,

    Limagito Team

  • 23 Apr

    Moving a file based on specific filename part to specific folder

    Q: Moving a file based on specific filename part to specific folder

    Hi there, looking if your software can do this please.

    1) Look at a filename, parse out from character 8-16 and capture it as a ID number

    2) look at the subfolders, find folder with same name, if doesn’t exist, create.

    3) move the file to that location.

    Here is some more specific example

    PDF Name: 055400E900105028-DEN-20210412_12.pdf

    Folder name to search for, and if not exists, create and move the data.

    900104028

    The bolded number is the ID number we need to catch/reference.

    I think it could just skip the file in this ‘rule’ if the length of the file is not ok which would mean it doesn’t contain an ID number.

    For this 1 rule/purpose these files come from a third party provider which should be pretty consistent and contain that number.

    The problem is some folders contain only the ID and is missing the buffer 0’s we put in front.

    So pdf may say 000000465 but the folder that already exists may be called 465 ☹

    Hopefully your tool can assist in more than one way (which it looks like it can!)

    A: Yes this should be possible. We prepared some screenshots to get you started.

    1.You can use any Source but in this example we used a WIN folder:

    Limagito File Mover WIN as Source

    2. File Filter Setup

    The minimum file length we need is 20 (this includes the file extension). We are using the RegEx Include File Filter:

    ^[^|/\<>:?”*]{20,}$

    Limagito File Mover minimum length filter

    3.Now we need some Pascal Script to achieve the customer request:

    Be sure to set the ctOutputPath Constant to the Destination path you are using. In our example the Destination path will be ‘C:\Test\Out_Pdf\’.

    When the File ID starts with 0 then we’ll check if the ID as subfolder exists without the zeros. If it exists we’ll use that one but when not, then the complete ID will be used to create a new destination subfolder.

    Limagito File Mover Pascal Script option

    Var
      tmpDummyPath: String;
      tmpSubPath: String;
    Const
      ctOutputPath = 'C:\Test\Out_Pdf\';
    Begin
      psExitCode := 0;
      tmpSubPath := Copy(psFilename, 8, 9);
      psLogWrite(1, '', 'Stripped ' + tmpSubPath + ' from ' + psFilename);
      //
      IF Copy(tmpSubPath, 1, 1) = '0' Then
      Begin
        If Not DirectoryExists(ctOutputPath + tmpSubPath) Then
        Begin
          tmpDummyPath := tmpSubPath;
          Repeat
            tmpDummyPath := Copy(tmpDummyPath, 2, length(tmpDummyPath) - 1);
            If DirectoryExists(ctOutputPath + tmpDummyPath) Then
            Begin
              tmpSubPath := tmpDummyPath;
              Break;
            End;                  
          Until Copy(tmpDummyPath, 1, 1) <> '0';     
        End;  
      End;
      // The End
      psVSA := tmpSubPath;
      // Check
      If psVSA <> '' Then
        psExitCode := 1;
    End.

    Limagito File Mover On Destination Pascal Script

    4. WIN as Destination setup. Important because for this request we need a WIN as Destination.

    Limagito File Mover WIN as Destination

    Important, be sure the ctOutputPath Constant in the previous Pascal Script is the same as this path.

    Limagito File Mover WIN as Destination Path

    Please enable and set the Create SubDir option to:  %VSA

    Limagito File Mover WIN as Destination SubPath

    5. Result

    Source Files:

    The file RegEx filter will ignore a file when its length < 20. In this case file ‘055400E9001050.pdf’ will not be used.

    Limagito File Mover Source Files

    Destination Subfolders:

    • Subfolder 105208 was already available and was used because of the ‘zero’ prefix in the ID number.
    • Subfolder 900105028 was created by our File Mover.

    RunTime Log:

    File ‘055400E000105028-DEN-20210412_12 – Copy.pdf’ was copied to ‘C:\Test\Out_Pdf\105028\’ because this already existed. The Pascal Script removed the zeros from the ID number and checked if it already was available.

    File ‘055400E900105028-DEN-20210412_12.pdf’ was copied to ‘C:\Test\Out_Pdf\900105028\’. The ID number has no ‘zero’ prefix so the complete ID number was used to create the subfolder.

    Limagito File Mover RunTime Log

    As you see many options are possible with Limagito File Mover so don’t hesitate to ask.
    If you need any help with this ‘specific filename part to specific folder’ request, please let us know.

    Best Regards,

    Limagito Team

    By Limagito-Team Pascal Script WIN , ,
  • 10 Mar

    I have a load of FTP sites that customer upload to, difficult to manage

    Q: Have a request. I have a load of FTP sites that customer upload to and currently we have a Limagito move on each of those folders – we now have too many of them to manage. Am trying to cut these down to one move per group of users.

    So, if a file arrives in a folder ABCD the move will pick it up, report to the user that a file has arrived and place it in their User folders with an append to the name telling them that it arrive in folder ABCD. So customer called ABCD has uploaded a file named ‘my files to you’ to their folder called ABCD. The file(s) are picked up and moved to a new folder with and rename ‘ABCD-my files to you’. Pretty sure this is possible here. But have had bit of play around with it but its defeating me!!!

    A: So the FTP server has a root folder with 1 subfolder for each customer like

    D:\Root\CustomerA
    D:\Root\CustomerB
    D:\Root\CustomerC
    Limagito will scan D:\Root and will pickup files from subfolder CustomerA and move them to another folder with the prefix of CustomerA-filename.pdf
    Limagito will scan D:\Root and will pickup files from subfolder CustomerB and move them to another folder with the prefix of CustomerB-filename.pdf

    1.Please add the following ‘On Destination’ Pascal Script:
    LimagitoX File Mover Pascal Script

    Begin
      psExitCode:= 1;
      // ... add your code here
      psVSA := psStringReplace(psFilePath, psSourcePath, '');
      psVSA := psStringReplace(psVSA, '\', '');
    End.

    Limagito File Mover On Destination Pascal Script
    2. Add the following Destination File Renaming:

    Limagito File Mover File Renaming option
    Limagito File Mover File Renaming setup
    If you need any help with this ‘load of FTP sites’ request, please let us know.

    Best Regards,

    Limagito Team

    By Limagito-Team Pascal Script WIN
1 19 20 21 22 23 24 25 29
SEARCH