This is what im trying to do.
A pdf is uploaded to my uploads directory. Named abc activity.pdf or abc page2.pdf
the pdf could be from different clients. so I want to pull the ABC or a certain amount of char out of the name to populate the destination #Property# field. and rename the pdf to be the date and the file name such as Jan272011-ABC.pdf or Jan272011-ABC2.pdf as needed.

There are several clients so they all have there own technet\property\CLIENT NAME\reports area.

So the file may be abc activity.pdf and i need to compare the ABC and if there Clientname directory is ABCInc it would change the #Property# to ABCInc. so maybe search the property directory for the Client Directory Names and compare them for the right directory?

Then I want to send them a email with the attachments wether it be 1 or more as i have in my cfmail section. I believe that one is correct to do it. Then I want a email sent to me stating who recieved a report and what the report name was. I know what i have isnt correct.

Any thought on how to accomplish this

Thanks in advance!!

<CFDIRECTORY Name="GetFiles" ACTION="List" DIRECTORY="D:\home\wwwroot\technet\Uploads\"
filter="*.*">

<CFLOOP QUERY="GetFiles">
<CFIF Type IS "File">
    <cffile action="rename"
        source="D:\home\wwwroot\technet\Uploads\#name#"
        destination="D:\home\wwwroot\technet\#property#\reports\#DateFormat(DateAdd('d', -1, MyDateTime),'mmmm dd, yyyy')# #Name#">

</CFIF>
</CFLOOP>

<CFMAIL TO= "me@u.com"
query="get_attachments"
    FROM="me@u.com"
    CC="me@u.com"
    server = "mail.u.com"
    SUBJECT=" Activity Report">

<cfloop query="">
<cfmailparam file="#get_attachments.location#/#get_attachments.name#">
</cfloop>

Dear client,



Attached is your report for your property please contact us with any questions or concerns you may have.

Thank You
</CFMAIL>


<CFMAIL TO= "me@yahoo.com"
query="get_attachments"
    FROM="me@u.com"
    SUBJECT="Reports sent"
    type="text">

Reports were sent to the following Clients

#clientName#

<cfloop query="">
#get_attachments.name#
</cfloop>
</CFMAIL>

Recommended Answers

All 7 Replies

Your question's a little confusing. What's your real goal in plain english, not code? To identify files by client, or somethin else ...?

Also, what is a #Property# in this context?

Your question's a little confusing. What's your real goal in plain english, not code? To identify files by client, or somethin else ...?

Also, what is a #Property# in this context?

I am trying to take pdf's that have been uploaded to the server and create a script that is scheduled to move those files to different client reports directory based on the filename then email them the reports then email me who recieved reports. And propertyname is the clients directory. which would be different based on the files.

It's doable with string and date functions. But do the files always follow a standard pattern

ie file name = {clientName}_xxxxxx.pdf?

In your example they don't. abc_activity.pdf and client ABCInc. Also, if the file name already exists in the client directory, how do you want to handle it?

Ok I figure a query with contains might work and yes it will always have the client name first. It should never run across a file that already exist as it uses the date as part of the file name when it renamed. And if it does it will make it unique when it renames so I think I'm good there

You shouldn't need a query. Just use string functions as you loop through #GetFiles#. Either use left() to get X characters, or if there's always a space after the client name, use list functions. Then grab the file extension and create the new file name

<!-- split for readability --->
<cfset clientName = listFirst("abc xxxxx.pdf", " ")>
<cfset ext     = listLast("abc xxxxx.pdf", ".")>
<cfset theDate = DateFormat(DateAdd('d', -1, MyDateTime),'mmmm dd, yyyy'))>
<cfset newName = theDate & clientName &"."& ext>

It should never run across a file that already exist as it uses the date as part of the file name when it renamed. And if it does it will make it unique when it renames

Well date alone isn't as unique as date + timestamp. As far as renaming, it'll overwrite any existing file. If you don't want that, you have to handle the making it unique yourself.

This has been resolved see solution...

<CFDIRECTORY Name="GetFiles" ACTION="List" DIRECTORY="D:\home\wwwroot\technet\Uploads\" filter="*.pdf">

<cfset mydatetime=now()>

<CFLOOP QUERY="GetFiles">
<CFIF Type IS "File">
<cfif #GetFiles.Name# Contains 'ABCInc'>
  <cfset #Property# = 'ABC'>
  	<cffile action="rename"
  	    source="D:/home/wwwroot/technet/Uploads/#GetFiles.Name#"
		destination="D:/home/wwwroot/technet/property/#property#/temp/#DateFormat(DateAdd('d', -1, MyDateTime),'mm dd, yyyy')# #Name#">


<cfelseif #GetFiles.Name# contains 'XYZ'>
  <cfset #Property# = 'XYZ'>
  	<cffile action="rename"
  	    source="D:/home/wwwroot/technet/Uploads/#GetFiles.Name#"
		destination="D:/home/wwwroot/technet/property/#property#/temp/#DateFormat(DateAdd('d', -1, MyDateTime),'mm dd, yyyy')# #Name#">


<cfelse>
  <cfset #Property# = 'BadCollection'>
  	<cffile action="rename"
  	    source="D:/home/wwwroot/technet/Uploads/#GetFiles.Name#"
		destination="D:/home/wwwroot/technet/property/#property#/temp/#DateFormat(DateAdd('d', -1, MyDateTime),'mm dd, yyyy')# #Name#">
</cfif>
</CFIF>
</CFLOOP>


<!-- Now send the files to the clients and archive the Files -->

<!-- Send Email to ABC -->

<cfinclude template="../technet/source/ABC Email.txt">

<!-- Send Email to XYZ -->

<cfinclude template="../technet/source/XYZ Email.txt">

Glad you figured it out. Just be aware CONTAINS matches substrings too. So sometimes it matches more than you want it too. Also, if the cffile code is the same for all 3, just write it once. The code'll be simpler

ie

<CFDIRECTORY Name="GetFiles" ACTION="List" DIRECTORY="D:\home\wwwroot\technet\Uploads\" filter="*.pdf">
<cfset mydatetime=now()>
<!--- removed excess # signs --->
<CFLOOP QUERY="GetFiles">
<cfif GetFiles.Name Contains 'ABCInc'>
  <cfset Property = 'ABC'>
<cfelseif GetFiles.Name contains 'XYZ'>
  <cfset Property = 'XYZ'>
<cfelse>
  <cfset Property = 'BadCollection'>
</cfif>
<cffile action="rename"
    source="D:/home/wwwroot/technet/Uploads/#GetFiles.Name#"
    destination="D:/home/wwwroot/technet/property/#property#/temp/#DateFormat(DateAdd('d', -1, MyDateTime),'mm dd, yyyy')# #Name#">

</CFLOOP>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.