Filters

  • 17 Oct

    Q&A 27: Check the length of a filename in LimagitoX File Mover

    Q: I want to check the length of a filename. We have a file renaming scheme that truncates the filename to a certain max length and adds a string to keep the file unique. Is it possible to add the string only when the filename gets truncated? or alternatively create a rule that only works if the filename is shorter than say 35 characters and another roule that works on files with a longer filename.
    A: Yes this is possible. We added 2 examples in this blog entry.
    1. First example will use the complete filename length and 2 rules.
    2. Second example will use the filename without extension and 1 rule with 2 destinations.

    First Example

    Please add two rules with the same source.

    We used the following include filter for the first rule:

    File Filter Setup > RegEx Tab > Include Filter

    ^[^|/\<>:?”*]{1,35}$
    Due to this RegEx file filter in the first rule it will include Filenames with length 1 .. 35 char

    LimagitoX File Mover RegEx File Filter

    We used the following include filter for the second rule:

    File Filter Setup > RegEx Tab > Include Filter

    ^[^|/\<>:?”*]{36,}$
    Due to this RegEx file filter in the second rule it will include files with length longer than 35 char (36 to ..)

    LimagitoX File Mover File Length RegEx Check

    Second Example

    We added a second example because the user had the following remark: “again thank you for your help the expression is working well, but it counts all the characters including the extension, I’m just trying to avoid bugs (some extensions are 3 char other are 4).”

    In this second example the length of the filename without file extension will be important. We’ll use one rule with 2 destinations. Depending on the length of the filename (without extension) it will use the first or second destination.

    >We added a Windows folder as Source:

    LimagitoX File Mover File Length example

    >We added two Destinations (both Windows folders). Depending on the length of the filename (without extension) it will use the first or second destination.

    LimagitoX File Mover File Length example

    > Open ‘Pascal Script’ Setup (Moving Rule Menu item):

    LimagitoX File Mover Pascal Script menu item

    >Please add the following ‘ On Destinations‘ Pascal Script. We have set the Constant ‘ctMaxLen’ to 10 in our second example (you can change this). Filenames without extension and longer than 10 will go to the second Destination (ID2). The rest of the files will go the the first Destination (ID1).

    Var
      tmpFileExt: String;
      tmpFileName: String;
      tmpLength: Integer;
    Const
      ctMaxLen = 10;  
    Begin
      psExitCode:= 0;
      // ... add your code here
      // psDestinationID	     'String' i.e. ID1, ID2,.. 
      tmpFileExt := ExtractFileExt(psFilename);
      tmpFileName := psStringReplace(psFilename, tmpFileExt, '');
      tmpLength := Length(tmpFileName);
      psLogWrite(1, '', 'Check length of ' + tmpFileName + ', Result: ' + IntToStr(tmpLength));
      // Default Do not Copy/Move
      psExitCode := -1;
      // Check first Destination, Copy/Move when equal of lower than ctMaxLen
      If (psDestinationID = 'ID1') And (tmpLength <= ctMaxLen) Then
      Begin
        psLogWrite(1, '', 'Destination ID1 will be used');
        psExitCode := 1;
      End;  
      // Check second Destination, Copy/Move when higher than ctMaxLen
      If (psDestinationID = 'ID2') And (tmpLength > ctMaxLen) Then
      Begin
        psLogWrite(1, '', 'Destination ID2 will be used');
        psExitCode := 1;
      End;  
    End.

    LimagitoX File Mover File Length Pascal Script

    >RunTime Log result. Files longer than 10 will use the second Destination (ID2).

    LimagitoX File Mover RunTime Log

    If you need any help with this ‘length of a filename’ request, please let us know.

    Best Regards,

    Limagito Team

    By Limagito-Team Filters Q&A
  • 17 Apr

    How-To use a csv file as filter and destination path in LimagitoX File Mover

    Another example of how Pascal Script can be used. In this how-to we’ll explain you how the content of a csv file can be used to filter the source file and at the same time this csv file will be used to set the destination path.

    In this example we use C:\Test\Demo as base folder. It contains 3 subfolders which will be used by the Moving Rule.

    1. C:\Test\Demo\Csv  :  contains the Csv file which we will scan for its content. The content will give us the file filter and destination path.
    2. C:\Test\Demo\In  :  folder will be used as source of the moving rule
    3. C:\Test\Demo\Out  :  folder will be used as destination path. We’ll receive this info from the csv file.

    In the Csv subfolder we created an excel file. First column contains the filename filter. We’ll search for files which contain this string in its filename. The second column is used for the destination path when this file is found.

    Next we did an export of this excel file to csv. We need this cvs file for our Pascal Script.

    Content of the Source Folder:

    Select this folder in the Source Setup (WIN).

    Setup of the File Filter. Important, select RegEx Include filter and add %VSB as filter.

    Open the Pascal Script Setup:

     

    Add the following ‘On Rule Begin’ Pascal Script. Don’t forget to adjust the ctCsvFile constant (depends on your setup).

    Var
      iList: Integer;
      tmpList: TStringList;
      tmpEntry: String;
      tmpName: String;
      tmpCount: Integer;
      tmpPos: Integer;
    Const
      ctCsvFile = 'C:\Test\Demo\Csv\List.csv';
      ctCsvSep = ';';
    Begin
      psExitCode:= 0;
      psVSA := '';
      psVSB := '';
      // ... add your code here
      Try
        tmpList := TStringList.Create;
        Try
          tmpList.LoadFromFile(ctCsvFile);
          If tmpList.Count > 0 Then
          Begin
            tmpCount := tmpList.Count - 1;
            For iList := 0 to tmpCount Do
            Begin
              tmpEntry := Trim(tmpList.Strings[iList]);
              tmpPos := Pos(ctCsvSep, tmpEntry);
              If tmpPos <> 0 Then
              Begin
                tmpName := Copy(tmpEntry, 1, tmpPos-1);
                If iList = tmpCount Then
                  psVSB := psVSB + '.*' + tmpName + '.*'
                Else
                  psVSB := psVSB + '.*' + tmpName + '.*|'
              End;
            End;
            psVSA := tmpList.CommaText;
            // Debug Info
            psLogWrite(1, '', 'psVSA: ' + psVSA);
            psLogWrite(1, '', 'psVSB: ' + psVSB);
            // Set psExitCode
            If (psVSA <> '') And (psVSB <> '') Then
              psExitCode := 1;
          End;
        Except
          psLogWrite(1, '', 'Load Script File Exception');
        End;
      Finally
        tmpList.Free;
      End;
    End.

    Add the following ‘On Destination’ Pascal Script.

    Var
      iList: Integer;
      tmpList: TStringList;
      tmpEntry: String;
      tmpName: String;
      tmpPath: String;
      tmpCount: Integer;
      tmpPos: Integer;
    Const
      ctCsvSep = ';';
    Begin
      psExitCode:= 0;
      psVSC := '';
      // ... add your code here
      Try
        tmpList := TStringList.Create;
        Try
          tmpList.CommaText := psVSA;
          If tmpList.Count > 0 Then
          Begin
            tmpCount := tmpList.Count - 1;
            For iList := 0 to tmpCount Do
            Begin
              tmpEntry := Trim(tmpList.Strings[iList]);
              tmpPos := Pos(ctCsvSep, tmpEntry);
              If tmpPos <> 0 Then
              Begin
                tmpName := Copy(tmpEntry, 1, tmpPos-1);
                If Pos(tmpName, psFileName) <> 0 Then
                begin
                  tmpPath := Copy(tmpEntry, tmpPos+1, length(tmpEntry)-tmpPos);
                  If tmpPath <> '' Then
                  Begin
                    psVSC := tmpPath;
                    Break;
                  End;
                End;
              End;
            End;
            // Debug Info
            psLogWrite(1, '', 'psVSC: ' + psVSC);
            // Set psExitCode
            If (psVSC <> '') Then
              psExitCode := 1
            Else
              psLogWrite(1, '', 'Could not find a path for: ' + psFileName);
          End;
        Except
          psLogWrite(1, '', 'Find Destination Path Exception');
        End;
      Finally
        tmpList.Free;
      End;
    End.

    Add a WIN Destination:

    Set ‘Select Directory’ to %VSC

    Enable and trigger the rule. The Source files will be filtered and moved to the destination as set in the csv file.

    Destinations created with information from the csv file:

    Destination content example:

    This is just an example of what can be done using Pascal Script. If you need any help using Pascal Script, please let us know.

    Regards,

    Limagito Team

    By Limagito-Team Filters Pascal Script ,
  • 09 Oct

    File Types Filter option

    We’re adding a new feature called ‘File Type Filter’ (WIN as Source). It was an idea of one of our users. This option will check the header of the file and is useful when no file extension is available. Like always, feedback = much appreciated. Please let us know if you would like us to add other extension types.

    Enable the types you would like to filter (Include and Exclude filter available):

    types-filtersetup-01

    We’ve add an option called ‘Add Type Extension’ so that the correct file extension can be added. You can edit our default extension.

    types-filtersetup-02

    We’ve also added a file filter option which decides to exclude files with or without an extension.

    types-filtersetup-03

    Regards,

    Limagito Team

     

    By Limagito-Team Filters ,
1 3 4 5 6 7
SEARCH