File Mover Blog

  • 28 May

    Create an empty file named done.txt as all the files have been moved

    Q: We are using your software for some simple file moving automation. We find it very reliable and we would like to convert our existing CMD and ps scripts to Limagito rules. We have a script which performs the following steps:

    • Copy a directory and its contents from an FTP source only if the directory name matches a certain pattern (LQJ_yyyymmdd) > OK
    • Transfer the contents of the directory to an FTP destination in the folder /Replica/yyyymmdd/LQJ > OK
    • Create an empty file named done.txt as soon as all the files have been moved to the destination (step 2) in the FTP folder /Replica/yyymmdd

    Could you give me a hint about how to perform the last step?

    A: This is possible using some Pascal Script we created for you.

    Please open the Pascal Script setup:

    limagito file mover pascal script

    • Enable and Add the following ‘On Rule Begin’ Pascal Script. The result of psVSB will be used as parameter (%VSB) in the directory filter setup.
    Begin
      psExitCode:= 1;
      // ... add your code here
      psVSA := FormatDateTime('YYYYMMDD', Now);
      psVSB := '*_' + psVSA + ';' + '*\*_' + psVSA + '\*';
      //
      psLogWrite(1, '', psVSB);
    End.
    

    limagito file mover on rule begin pascal script

    • Enable and add the following ‘On Rule End’ Pascal Script. This script will create the Done.txt file ‘On Rule End’ when all files were transferred successfully. Don’t forget to adjust the ctDonePath ( must end with a \ ).
    Var
      tmpList: TStringList;
      tmpFile: String;
    Const
      ctDonePath = 'C:\Test\Pressor\Replica\';
    Begin
      psExitCode:= 0;
      tmpFile := ctDonePath + psVSA + '\Done.txt';
      // ... add your code here
      If (psCurrentFilesSrcError = 0) And (psCurrentFilesDstError = 0) Then
      Begin
        tmpList := TStringList.Create;
        Try
          tmpList.Text := 'Dummy Content';
          Try
            psCreatePath(ctDonePath + psVSA);
            tmpList.SaveToFile(tmpFile);
            // Debug
            psLogWrite(1, '', 'Save To File ' + tmpFile + ' Successful');
            // set ExitCode Successful
            psExitCode := 1;
          Except
            psLogWrite(1, '', 'Save To File ' + tmpFile + ' Error');
          End;
        Finally
          tmpList.Free;
        End;
      End
      Else
        psLogWrite(1, '', tmpFile + ' will not be created due to source or desitnation error(s)');
    End.
    

    limagito file mover on rule end pascal script

    • Directory setup, be sure to enable ‘Include Subdirectories’ and ‘Exclude Basedirectory’:

    limagito file mover directory setup

    • Set Dir Name include filter to:  %VSB

    The value of parameter %VSB will be set in the ‘On Rule Begin’ Pascal Script.

    limagit file mover directory name filter

    • Set Dir Name exclude filter to exclude certain unwanted subfolders:

    limagito file mover directory exclude filter

    • Be sure to allow the use of parameters in the Directory Name filter:

    limagito file mover directory filter

    • Destination setup:

    Limagito file mover destination setup

    limagito file mover win as destination

    limagito file mover windows folder as destination

    #filetransfer #mft #filemanagement

    If you need any info  about this ‘Create an empty file named done’ request, please let us know.

    Best regards,

    Limagito Team

    By Limagito-Team Filters Pascal Script ,
  • 28 May

    Delete all contents of a destination folder before files are moved

    Q: Is there a way to delete all contents of a destination folder before files are moved/not just overwriting them? I am unzipping a large folder with files daily, most files are named the same thing so they can overwrite them. Have a few that are named with dates and times so they just end up staying in the folder.

    A: If the unzip folder is always the same, the following solution could help you. We added a script that will delete all files and subfolders when ‘On Rule Begin’ is triggered. The path you need to use in the script is the one you will use in your UNZIP as Destination setup.

    – Open Pascal Script Setup

    limagito file mover pascal script

    • Enable and Add the following ‘On Rule Begin’ Pascal Script. In this example our Unzip path = C:\Test\Out\UNZIP\

    Don’t forget to adjust the ctOutputPath const, must end with a \

    Const
      ctOutputPath = 'C:\Test\Out\UNZIP\';
    Begin
      psExitCode:= 1;
      // ... add your code here
      psLogWrite(1, '', 'Delete Tree: ' + ctOutputPath);
      psDeleteFiles(ctOutputPath, '*.*');
      psDeleteTree(ctOutputPath, True);
    End.
    

    Delete all contents of a destination

    #filetransfer #mft #filemanagement

    If you need any info  about this ‘Delete all contents of a destination’ request, please let us know.

    Best regards,

    Limagito Team

    By Limagito-Team Pascal Script WIN ZIP ,
  • 26 May

    Get a field value to rename a csv file

    Q: Get a field value to rename a file. I received a file with a specific filename every week which goes through various processes, after I have finished I need to send the original data with some extra data columns generated by our process back to the client using the original filename. Unfortunately, I cannot keep hold of the filename throughout the process but I can have a column in the return file which contains the original filename. Is there a way I can use Filmover to have a look at a specific column of a data file get the contents of it and use it to rename the file to that value then deleted the column that I got the information from? Bit complex but I thought I’d ask before exploring other avenues. The column that contains the original filename to be used and then deleted is called IMPNAME.

    A: Should be possible (we received an example file of the customer).

    • Please set filename filter to *.csv

    limagito file mover filename filter

    • Add ‘Pascal Script’ as Destination:

    limagito file mover pascal script as destination

    • Don’t forget to adjust the ctOutputPath Const (must end with a \ )
    Var
      iEntry, iIndex, iList: Integer;
      tmpFilename, tmpInputFile, tmpOutputFile: String;
      tmpEntryList, tmpFileList: TStringList;
    Const
      ctOutputPath = 'C:\Test\Out_Csv\';  // Must end with a \
      ctIMPNAME = 'IMPNAME';
    Begin
      psExitCode := 0;
      iIndex := -1;
      tmpInputFile := psFilePath + psFilename;
      tmpOutputFile := '';
      // ... add your code here
      tmpEntryList := TStringList.Create;
      tmpEntryList.Delimiter := ',';
      tmpEntryList.StrictDelimiter := True;
      tmpEntryList.QuoteChar := '"';
      tmpFileList := TStringList.Create;
      Try
        Try
          tmpFileList.LoadFromFile(tmpInputFile);
          tmpEntryList.DelimitedText := tmpFileList.Strings[0];
          For iEntry := 0 to (tmpEntryList.Count - 1) Do
          Begin
            If SameText(ctIMPNAME, tmpEntryList.Strings[iEntry]) Then
            Begin
              iIndex := iEntry;
              psLogWrite(1, '', 'Found ' + ctIMPNAME + ' at Column with Index ' + IntToStr(iIndex));
              Break;
            End;
          End;
          // Did we find 'IMPNAME'
          If iIndex <> -1 Then
          Begin
            tmpFileList.Strings[0] := psStringReplace(tmpFileList.Strings[0], ',"' + ctIMPNAME + '"', '');
            For iList := 1 to (tmpFileList.Count - 1) Do
            Begin
              tmpEntryList.DelimitedText := tmpFileList.Strings[iList];
              If tmpEntryList.Count > iIndex Then
              Begin
                If tmpOutputFile = '' Then
                Begin
                  tmpFilename := tmpEntryList.Strings[iIndex];
                  If tmpFilename <> '' Then
                    tmpOutputFile := ctOutputPath + tmpFilename + '.csv';
                End;  
                If tmpFilename <> '' Then
                Begin
                  tmpFileList.Strings[iList] := psStringReplace(tmpFileList.Strings[iList], ',"' + tmpFileName + '"', '');           
                  psLogWrite(1, '', 'Entry: ' + tmpOutputFile + ' : ' + tmpFileList.Strings[iList]);
                End;  
              End;
            End;
          End;
          // Save To File
          If tmpOutputFile <> '' Then
          Begin
            Try
              tmpFileList.saveToFile(tmpOutputFile);
              psExitCode := 1;
            Except
              psLogWrite(1, '', 'Error saving file: ' + tmpOutputFile);
            End;
          End;
        Except
          psLogWrite(1, '', 'Error loading file: ' + tmpInputFile);
        End;
      Finally
        tmpEntryList.Free;
        tmpFileList.Free;
      End;
    End.
    

    Get a field value

     

    #filetransfer #mft #filemanagement #csv

    If you need any info  about this ‘get a field value to rename a file’, please let us know.

    Best regards,

    Limagito Team

    By Limagito-Team CSV ,
1 24 25 26 27 28 29 30 136
SEARCH