Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to delete pdf files created on server using cfdocument pdf?

Guest
Jun 08, 2010 Jun 08, 2010

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.

2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Jun 08, 2010 Jun 08, 2010

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

...
Translate
Guest
Jun 08, 2010 Jun 08, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 08, 2010 Jun 08, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 08, 2010 Jun 08, 2010
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources