Copy link to clipboard
Copied
I am using <cfdocument format="pdf" ...
to create a dynamically named and generated .pdf and it works rather well. Navy managers can easily email the pdf to ships in the fleet and planning forces in the shipyards. (Planning data changes almost daily). However I have noticed that the pdf file stays on the server. Over time this could become a problem with numbers. Is there something I am missing to remove these pdfs over time. Other than a manual review and delete. This government server requires 4 logins and your right arm to update, so something auto is needed.
Using a ScheduledTask for this problem is something easy (and I think a common way to solve such problems)!
Just to give you a clue (or probably the whole solution, but it's not tested):
<cfset Variables.strDirPath = ExpandPath('./pdf')>
<cfset Variables.delDate = "#lsdateformat(dateadd('d',-7,now()),'dd.mm.yyyy')#">
<cfdirectory
directory="#Variables.strDirPath#"
name="qDir"
action="LIST"
filter="*.pdf" />
<cfloop query="qDir">
<cfif lsdateformat(qDir.DateLastModified) EQ Variables.de
Copy link to clipboard
Copied
You could use the "remove" attribute of the cfmailparam tag (introduced with Coldfusion 8.01). That means, after emailing the PDF with cfmail the file will be deleted. But with this soution the file can be emailed only once (but you can circumvent that behavior by creating the file again for a new email)!
Other idea is to use a ScheduledTask. Simply create a cfml document that collects the files of a spcial folder, check their file dates and delete the files if necessary. Connect ScheduleTask and document with Coldfuison Administrator (Debugging & Loggin -> Scheduled Tasks) and run the task daily.
Copy link to clipboard
Copied
Thanks for responding:
I am not using cfmail - I am leaving it up to the user to print save or email.
Your second option sound good but I really was hoping I was just missing something easy (new to cf).
I did try giving the pdf the same name but I was having lots of troble with always returning the cached version.
Copy link to clipboard
Copied
Using a ScheduledTask for this problem is something easy (and I think a common way to solve such problems)!
Just to give you a clue (or probably the whole solution, but it's not tested):
<cfset Variables.strDirPath = ExpandPath('./pdf')>
<cfset Variables.delDate = "#lsdateformat(dateadd('d',-7,now()),'dd.mm.yyyy')#">
<cfdirectory
directory="#Variables.strDirPath#"
name="qDir"
action="LIST"
filter="*.pdf" />
<cfloop query="qDir">
<cfif lsdateformat(qDir.DateLastModified) EQ Variables.delDate>
<cffile action="delete" file="#Variables.strDirPath#\#qDir.name#">
</cfif>
</cfloop>
Message was edited by: RichinternetFrank Reason: changed filter attribute to pdf