File Mover Blog

  • 12 Jul

    Adjust datepart of a filename with Limagito File Mover

    Q: Adjust datepart of a filename with Limagito File Mover. I have a file name “thisfile_20210712” and after transfer I would like to reduce one day “thisfile_20210711”. I can try to figure out with regex but what if the day is 20210801” that would be challenge for regex . I don’t know if you have any thing to allow external window host script to run after the job to fix this.

    A: Yes this is possible using some Pascal Script. If you think this is too difficult for you, just contact us and we’ll help.

    We received an example file of the customer:

    This is the example  “thisfile_20210711_new.pdf”

    Expected:  “thisfile_20210710_revised.pdf”

    1.Our Source is a Windows Folder.

    Limagito File Mover Windows Folder as Source

    2. Add the following ‘OnDestination’ Pascal Script. This script will strip and adjust the datepart in the filename.

    Limagito File Mover Pascal Script Menu

    Limagito File Mover On Destination Pascal Script

    Var
      iList: Integer;
      tmpDate: TDateTime;
      tmpDatePart: String;
      tmpList: TStringList;
      
    Function GetDateFromString(const aInput: String): TDateTime;
    var
      wYear, wMonth, wDay: Word;
    Begin
      wYear := StrToInt(Copy(aInput, 1, 4));
      wMonth := StrToInt(Copy(aInput, 5, 2));
      wDay := StrToInt(Copy(aInput, 7, 2));
      Try
        Result := EncodeDate(wYear, wMonth, wDay);
      Except
        Result := 0;
      End;  
    End;  
    
    Begin
      // thisfile_20210711_new.pdf
      psExitCode:= 0;
      // ... add your code here
      tmpList := TStringList.create;
      Try
        tmpList.delimiter := '_';
        tmpList.DelimitedText := psFileName;
        If tmpList.Count >= 3 Then     
        Begin
          tmpDatePart := tmpList.Strings[1];
          psLogWrite(1, '', 'DatePart from File ' + psFilePath + psFileName + ': ' + tmpDatePart);     
          tmpDate := GetDateFromString(tmpDatePart);
          tmpDate := psIncDay(tmpDate, -1);
          //
          If Not (tmpDate = 0) Then
          Begin
            tmpList.Strings[1] := FormatDateTime('YYYYMMDD', tmpDate);
            // Iterate
            For iList := 0 to (tmpList.Count-1) Do
            Begin
              If iList = 0 Then
                psVSA := tmpList.Strings[iList]
              Else  
                psVSA := psVSA + '_' + tmpList.Strings[iList];        
            End;  
            psLogWrite(1, '', 'Reesult psVSA: ' + psVSA);        
            psExitCode := 1;
          End
          Else          
            psLogWrite(1, '', 'GetDateFromString Error, ' + tmpDatePart);
        End
        Else
          psLogWrite(1, '', 'Count FileName _ Parts Error, ' + psFileName);        
      Finally
        tmpList.free;
      End;  
    End.
    

    3. In your Destination setup we’ll use the File Renaming option to rename the originale filename to:

    • the adjusted filename (%VSA)
    • ‘new.pdf’ part to ‘revised.pdf’

    Limagito File Mover File Renaming

    Limagito File Mover File Renaming

    4. RunTime Log Result:

    Limagito File Mover RunTime Log Result

    #FileTransfer

    If you need any info about this new ‘Adjust datepart of a filename’ option, please let us know.

    Best regards,

    Limagito Team

  • 11 Jul

    Generate an xml on output with the same name as the input filename

    Q: I was wondering if Limagito File Mover can generate an xml on output with the same name as the input filename.

    A: Yes this is possible. In this case we’ll add a second Destination. This ‘Pascal Script’ Destination will create the Xml file. It will only generate this xml if the first Destination succeeds.

    1.You can use any Source. In our example we used a Windows Folder.

    2.We only want write the Xml file if the first Destination Succeeds. Therefore we have to select ‘Destination Memory & Exit Cyclus On Error’ as Destination Option in the Function Setup.

    Limagito File Mover Function Setup

    3. Add Pascal Script (PScript) as Second Destination

    Limagito File Mover Pascal Script as Destination

    4. Pascal Script Destination Setup

    We received the following example xml from the user (but we can generate other xml structures too):

    <?xml version=”1.0″ encoding=”iso-8859-1″?>
    <AdWatchData>
    <adwatch-ad-number>HOU4001521801</adwatch-ad-number>
    <file_name>HOU4001521801.pdf</file_name>
    </AdWatchData>

    We created the following Pascal Script which will generate the xml file. Please don’t forget to adjust the ‘ctOutputPath’ Const which will be different in your case. In our example we’ll create the xml file in: ‘C:\Test\Out\’.

    Limagito File Mover generate xml on output

    Var
      tmpFileExt: String;
      tmpFileName, tmpFileNameNoExt: String;
      tmpXml: TStringList;
    Const
      ctOutputPath = 'C:\Test\Out\'; // must end with a \
    Begin
      psExitCode:= 0;
      tmpFileExt := ExtractFileExt(psFileName);
      tmpFilenameNoExt := psStringReplace(psFileName, tmpFileExt, '');
      tmpFileName := tmpFileNameNoExt + '.xml';
      // Create XML
      tmpXml := TStringList.Create;
      Try
        tmpXml.Add('')
        tmpXml.Add('');
        tmpXml.Add('' + tmpFileNameNoExt + '');
        tmpXml.Add('' + psFileName + '');
        tmpXml.Add(''); 
        // Save to File  
        Try
          tmpXml.SaveToFile(ctOutputPath + tmpFileName);
          psExitCode := 1;   
        Except
          psLogWrite(1, '', 'SaveToFile Error, File: ' + ctOutputPath + tmpFileName);
        End;
      Finally
        tmpXml.Free;
      End;  
    End.

    5.RunTimeLog Result:

    Limagito File Mover RunTime Log

    6. Generated Xml on Output:

    Limagito File Mover generate xml on output

    #FileTransfer

    If you need any info about this new ‘Generate an xml on output’ option, please let us know.

    Best regards,

    Limagito Team

    By Limagito-Team XML ,
  • 10 Jul

    Google Cloud Storage as Destination in Limagito File Mover

    Google Cloud Storage as Destination was added in Limagito File Mover version v2021.7.8.0. In the following example we’ll upload a File to Google Cloud Storage.

    1.First we added a Windows folder as Source:

    Limagito File Mover Windows Folder as Source

    2. Next we added ‘Google Cloud Storage (G Cloud)’ as Destination:

    Limagito File Mover Select Destination

    3.We want the files to be copied into the ‘/Test’ folder of Bucket ‘limagito’. At the moment we use the ‘Service Account JSON Private Key’ as authentication. You need to generate this in your Google Cloud Setup and after download import this JSON file using the Import Button.

    Limagito File Mover Goolge Cloud Setup

    Google Cloud Storage Service account key JSON file

    Don’t forget to set the Bucketname. In our case it is called ‘limagito’.

    Limagito File Mover Goolge Cloud Bucketname Setup

    Hit ‘Connect’ to test the connection:

    Limagito File Mover Google Cloud Storage Connection test

    4. RunTime Log Result:

    Limagito File Mover RunTime Log Result

    5. Result in the Google Cloud Storage Browser:

    Limagito File Mover Cloud Browser Result

    #FileTransfer

    If you need any info about this new ‘Google Cloud Storage as Destination’ option, please let us know.

    Best regards,

    Limagito Team

    By Limagito-Team Google
1 60 61 62 63 64 65 66 136
SEARCH