Q&A

  • 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
  • 15 Oct

    Q&A 26: Custom SMTP report with filename and transfer timestamp

    Q: Custom SMTP report. I am trying to set up SMTP notifications / Reports that will be sent out once a job runs. I am having the following trouble, I want the email to show the filename and timestamp of when it was transferred, I have this working but if there is multiple files it will send multiple emails, I want a single email per Rule that will one send out one email with file names and time each file was moved.
    A: We’ve added some screenshots to get you started.

    >Please open ‘Rule Events’ Setup in the ‘Moving Rule’ Menu:

    LimagitoX File Mover Rule Events

    >Select and enable ‘On Rule Begin’ event item. Within the ‘On Rule Begin’ event item:

    • Select Pascal Script tab and enable ‘Enable Pascal Script’.
    • Add the following Pascal Script:
    Begin
      // ... add your code here
      psVSA := '';
    End.

    LimagitoX File Mover Rule Events Setup

    >Select and enable ‘On Success’ event item. Within the ‘On Success’ event item:

    • Select ‘Options’ tab and enable ‘Trigger mail event after scan’.
    • Optionally you can enable ‘Enable On Success Events for LimagitoX Temporary Files’.

    • Select ‘Pascal Script’ Tab and enable ‘Enable Pascal Script’.
    • Add the following Pascal Script:
    var
      tmpList: TStringList;
      tmpTime: String;
    Begin
      // ... add your code here
      tmpList := TStringList.Create;
      Try
        // Read from psVSA
        tmpList.Text := psVSA;
        // Add To psVSA
        tmpTime := FormatDateTime('YYYY/MM/DD HH:NN:SS', Now);
        tmpList.Add(psFilePath + psFilename + ' @ ' + tmpTime);
        // Write to psVSA
        psVSA := tmpList.Text; 
      Finally
        tmpList.Free;
      End;  
    End.

    • Select ‘Email’ tab and enable ‘Enable Mail’
    • Setup SMTP server and Email itself. There is a test button available.

    • Important, in the mail body you’ll need to add:  %VSA
      • This %VSA will contain the file information added thanks to the previous Pascal Script

    • We used the gmail smtp server in this example but any other smtp server will work.

    >Result

    If you need any help with this custom SMTP report, please let us know.

    Best Regards,

    Limagito Team

    By Limagito-Team Q&A SMTP
  • 01 Aug

    Q&A 22: move a file and rename the file so it includes the directory name

    Q: I’m trying to move a file that’s within 1 directory and rename the file so that it includes the directory name

    Source: C:\Source1\File.txt

    Destination: C:\Destination\Source1_File.txt

    I want it to take the directory name that it is contained in, then string it to the front of the filename, but move it to it’s destination C:\Destination\.

    We would only want it to pertain to the previous directory by 1 level.

    • C:\Source1\File1.txt => C:\Destination\Source1_File1.txt
    • C:\Source1\Sub\File2.txt => C:\Destination\Sub_File2.txt

    A: Yes this is possible using some ‘Pascal Script’

    Let’s start with the Source, we added a Windows folder:

    LimagitoX file Mover Windows Folder as Source

    In the ‘Directory Filter’ setup we enabled include scanning of subdirectories (optional, is not a must):

    LimagitoX file Mover Include Subdirectories

    Destinations setup, important the first destination must be a ‘Pascal Script’:

    LimagitoX file Mover Destination Setup

    First Destination should be a ‘Pascal Script’. We used ‘Source1’ as default PreFix for the Source Root Folder (you can adjust this):

    Var
      tmpPos: Integer;
      tmpSubDir: String;
    Const
      ctRootPrefix = 'Source1';
    Begin
      psExitCode:= 1;
      // ... add your code here
      psVSA := '';
      tmpSubDir := '%SFS';
      tmpPos := pos('\', tmpSubDir);
      If tmpPos<>0 Then
      Begin
        psVSA := Copy(tmpSubDir, tmpPos + 1, Length(tmpSubDir) - tmpPos);
        psLogWrite(1, '', 'Stripped Prefix from SubDir: ' + tmpSubDir + ' : ' + psVSA);  
      End
      Else
        psVSA := ctRootPrefix;   
    End.

    LimagitoX file Mover Pascal script

    Second Destination is a windows folder where the source files should be moved/copied to:

    LimagitoX file Mover Windows Folder as Destination

    Enable and setup File Renaming in the Windows Destination:

    LimagitoX file Mover File Renaming

    File Renaming setup:

    • RegEx:   (.*)
    • Replacement:   %VSA_\1

    LimagitoX file Mover File Renaming Setup

    RunTime Log result:

    LimagitoX file Mover RunTime Log

    Output Folder result:

    If you need any help , please let us know.
    Regards,
    Limagito Team
    By Limagito-Team Q&A ,
1 4 5 6 7 8 9 10 17
SEARCH