web stats
How to delete files that are sent to the destination ? - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 07-17-2015, 12:38 AM
C3G C3G is offline
Mirth Newb
 
Join Date: Jun 2015
Posts: 13
C3G is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 07-17-2015, 07:22 AM
mbellio mbellio is offline
Mirth Newb
 
Join Date: May 2015
Posts: 6
mbellio is on a distinguished road
Default

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.
Reply With Quote
  #3  
Old 07-20-2015, 01:23 AM
C3G C3G is offline
Mirth Newb
 
Join Date: Jun 2015
Posts: 13
C3G is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 07-20-2015, 08:06 AM
mbellio mbellio is offline
Mirth Newb
 
Join Date: May 2015
Posts: 6
mbellio is on a distinguished road
Default

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 at 08:23 AM.
Reply With Quote
  #5  
Old 07-20-2015, 08:18 AM
clinjohn clinjohn is offline
OBX.2 Kenobi
 
Join Date: Apr 2015
Posts: 95
clinjohn is on a distinguished road
Default

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?
Reply With Quote
  #6  
Old 07-22-2015, 01:18 AM
C3G C3G is offline
Mirth Newb
 
Join Date: Jun 2015
Posts: 13
C3G is on a distinguished road
Default

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
Reply With Quote
  #7  
Old 07-22-2015, 11:31 AM
clinjohn clinjohn is offline
OBX.2 Kenobi
 
Join Date: Apr 2015
Posts: 95
clinjohn is on a distinguished road
Default

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.
Reply With Quote
  #8  
Old 07-23-2015, 02:18 AM
C3G C3G is offline
Mirth Newb
 
Join Date: Jun 2015
Posts: 13
C3G is on a distinguished road
Default

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
Reply With Quote
  #9  
Old 07-23-2015, 04:41 AM
flyerman flyerman is offline
OBX.2 Kenobi
 
Join Date: May 2015
Posts: 68
flyerman is on a distinguished road
Default

Do your filter based on file names key words?
Reply With Quote
  #10  
Old 07-23-2015, 05:22 AM
C3G C3G is offline
Mirth Newb
 
Join Date: Jun 2015
Posts: 13
C3G is on a distinguished road
Default

Hi Flyerman,

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

Rgds,
C3G
Reply With Quote
Reply

Tags
delete file, destination, postprocessor, script

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 07:32 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation