• 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 ,
  • 01 Aug

    Q&A 21: Generate a status file for each file which was successfully moved

    Q:  I need to know if a status file can be generated when a file is successfully moved that includes the source location?

    We would like a log file generated called 123456.pdf.log that contains the following data:

    Remote path: C:\upload\input\123456.pdf
    Affinity PDF has been transferred to distiller
    Delivery log name: C:\upload\output\123456.pdf.log

    The remote path is the location where the file was moved from
    The second line is just a text line
    The Delivery Log Name is the location where the file was placed and the name of the log file

    A: Yes this is possible using some Pascal Script.

    Let’s start with the Source. In our example it is a Windows Folder:

    ‘C:\Test\In_PDF\’.

    LimagitoX File Mover Windows Folder as Source

    Important, in the function Setup you need to set the ‘Destination Options’ to ‘Exit Cyclus on Error’. Reason is that we want to be 100% sure that the file was moved before we write the status file.

    LimagitoX File Mover Function Setup

    Destinations Setup, the first destination is the folder where the pdf needs to be moved to. The second destination is the ‘Pascal Script’ needed for the creation of the status file.

    LimagitoX File Mover Destinations

    We added a Windows folder as first Destination. Default Setup is ok.

    LimagitoX File Mover WIN as destination

    The second Destination is our ‘Pascal Script’ needed for the creation of the status file:

    Var
      tmpList: TStringList;
      tmpLogName: String;
      tmpLogPath: String;
    Const
      ctLogRootDir = 'C:\Test\Out\PDF';
    Begin
      tmpLogPath := ctLogRootDir + '%SFS\';
      psExitCode:= 1;
      // ... add your code here    
      tmpList := TStringList.Create;
      Try
        tmpLogName := '%SFN.log';
        Try    
          tmpList.Add('Remote path: %SFP%SFN'); 
          tmpList.Add('Affinity PDF has been transferred to distiller');
          tmpList.Add('Delivery log name: ' + tmpLogPath + tmpLogName);
          // Save
          psLogWrite(1, '', 'SaveToFile: ' + tmpLogPath + tmpLogName);
          tmpList.SaveToFile(tmpLogPath + tmpLogName);   
        Except
          psLogWrite(1, '', 'Log Create Error');
        End;  
      Finally
        tmpList.Free;
      End;  
    End.

    LimagitoX File Mover Pascal Script as Destination

    RunTime Log Result:

    Output Folder Result:

    If you need any help , please let us know.
    Regards,
    Limagito Team
SEARCH