Announcement

Collapse
No announcement yet.

How to delete files that are sent to the destination ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to delete files that are sent to the destination ?

    Morning gents,

    Is there someone can help/tell me how to delete only files that are successfully sent to the destination ? Maybe I can do it with postprocessor script, but how ?

    Thank you in advance for your answers and helps… Script examples are welcome

    Rgds,
    C3G

  • #2
    Here's a quick script I threw together in the post-processor.

    Code:
    var File = java.io.File;
    if (FileUtil.deleteFile(new File($('FilePathAndName')))) {
        logger.error("File successfully deleted.");
    }
    else {
        logger.error("File could not be deleted.");
    }
    This should delete the file from the path and name given. The file path and name need to be put into a variable before the post-processor is run.

    Comment


    • #3
      Hi mbellio,

      First, thank you for your fast reply.

      I tried to add your script into the post-processor of my channel, but it doesn't work.

      As mentionned, I created a variable "FilePathAndName" where I pass the path and the file name as below :

      - //server_name/share$/folder/file_name.pdf
      I also tried with the syntax below :
      - \\server_name\share$\folder\file_name.pdf

      But without success

      Did I forget something ?? Or done something wrong ??

      Just for more information, currently my source channel use SMB protocol, but I have also another channel that use FTP protocol.

      Thank you in advance for your help...

      Regards,
      C3G

      Comment


      • #4
        I haven't worked with SMB before so my help from here on will be somewhat limited, but here is a post I found that includes a function which tries to connect to and read from a SMB filesystem.
        http://www.mirthcorp.com/community/f...31&postcount=5

        I've also found the fisheye link for SmbFileConnection, which includes a function to delete a file.

        http://www.mirthcorp.com/community/f...on.java?r=7707

        One last thing. I should have noted this before, but I forgot about it. The postprocessor will run whether or not the message is successful or not. You could create a Javascript destination which checks the previous destinations messages. Here's a quick way to check the previous destinations:

        Code:
        if ($('d5').toString().indexOf('SENT') != -1)
        	logger.error("Sent successfully. Do all neccessary deletion here");
        else
        	logger.error("Destination not succcessful. Don't do anything.");
        $('d5') is the destination which you are looking for. You can drag over the destination you want to check from the box on the right of the javascript editor.
        Hopefully those 2 links can lead you in the right direction (or maybe someone else can help you out here).
        Last edited by mbellio; 07-20-2015, 07:23 AM.

        Comment


        • #5
          Are the two of you discussing deleting files from the destination itself, or deleting files from the source once you know they've reached the destination?

          Comment


          • #6
            Morning Gents,

            @mbellio : Thank you again for your help. I will investigate this solution, but it seems to me quite heavy to run, however, for the moment I found a workaround with symbolic links. (one on SMB and one on FTP). Now from Mirth I work directly with symbolic links.

            For deletion of destination files I use the following command :

            Code:
            var del=new java.io.File($('File_Path_And_Name_File'));
            del['delete']();
            @clinjohn : The purpose is to delete files that are filtered in source and after been proceeded on destination. Do you have any recommendation on this way.

            Best regards,
            C3G

            Comment


            • #7
              I guess I'm wondering why you want to use Javascript or Java code for this. Can't you simply choose the Delete option for "After Processing Action" in the channel's Source configuration?

              I did myself recently run into a situation where I was trying to send files from one source to multiple destinations, with different files going to specific destinations at different intervals. I found that "After Processing Action" moved or deleted all the files that happened to be in its directory when any of them got sent. But I solved that by dividing my original channel into multiple channels, each with the same source but only one of the original destinations.

              Comment


              • #8
                Hi clinjohn,

                I cannot use "After Processing Action" because I use a filter.

                In my source, I search all *.pdf files, but I apply a filter to select only files with specific criteria before to send to destination.

                With "After Processing Action" it will delete all the *.pdf files. And in my case I want to delete only files that are filtered on the destination.

                Rgds,
                C3G

                Comment


                • #9
                  Do your filter based on file names key words?

                  Comment


                  • #10
                    Hi Flyerman,

                    No, is based on directories, because in the source I use the option "Include All Subdirectories".

                    Rgds,
                    C3G

                    Comment

                    Working...
                    X