cfdirectory - files with the same name - different extensions

I am using the following to display files that are hyperlinks.  Some departments have a .doc and a .pdf file with the same name.  They only want to display the .pdf if it exists otherwise display the .doc file.  Thanks for any help!

<body>
<cfdirectory name="getLinks" directory="d:\inetpub\wwwroot\docs\documents\#passname#\">

<cfoutput query="getLinks">
  <a href="../documents/#passname#/#getLinks.Name#" target="_blank"">#listfirst(getLinks.Name,'.')#</a><br>
</cfoutput>
</body>
dmwelterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kkhippleCommented:
http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/functb14.htm#wp1107735

Have a look at ListLast dmwelter...  

haven't worked with CFDIRECOTRY myself ... but this should work
this assumes you have the file listing in alphabetical order.. then the doc file should show up first and then the pdf file...


<body>
<cfdirectory name="getLinks" directory="d:\inetpub\wwwroot\docs\documents\#passname#\">

<CFSET thisFilename = "">

<cfoutput query="getLinks">

   <!--- check filename if it equals current file then display pdf file --->
   <CFIF ListFirst(getLinks.Name,'.') EQ ListFirst(thisFilename,'.')>
       <a href="../documents/#passname#/#thisFilename#" target="_blank"">#listfirst(getLinks.Name,'.')#</a><br>
   <CFELSE>
    <a href="../documents/#passname#/#getLinks.Name#" target="_blank"">#listfirst(getLinks.Name,'.')#</a><br>
   </CFIF>

   <CFSET thisFilename = getLinks.Name><!--- set filename --->


</cfoutput>
</body>
0
pinaldaveCommented:
Hi dmwelter,


<cfloop query="getLinks">
                                                                    <cfloop index = "ListElement" list = "pdf,doc">
                                                                        <cfdirectory
                                                                         action = "list"
                                                                         directory = "d:\inetpub\wwwroot\docs\documents\#passname#\"
                                                                         name = "getLinks"
                                                                         filter = "#trim(getLinks.filename)#.#ListElement#"
                                                                         >
                                                                         
                                                                         <cfif getfilename.recordcount>
                                                                               <a href="../documents/#passname#/#getLinks.Name#" target="_blank"">#listfirst(getLinks.Name,'.')#</a><br>
                                                                      </tr>
                                                                         </cfif>  
<cfexit>          
                                                                    </cfloop>
  </cfloop>
Regards,
---Pinal
0
pinaldaveCommented:
Hi dmwelter,
you may need to change few thigns but that is main logic. if i find the file with pdf file i will exit from loop.

Regards,
---Pinal
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

dmwelterAuthor Commented:
I get the following error and don't know how to correct it.  I'm obviously very new to ColdFusion.

Attribute validation error for tag cfloop.  
The value of the attribute query, which is currently "getLinks", is invalid.  
0
Tacobell777Commented:
You will need to have a list of file names first.
Lets say that file "someFile.dpf" does not exist, then show the word document, you would need to know the name of the file, i.e. "someFile" before you can create a link to it.

Unless there is only one file in the directory? Example;
use cfdirectory to get the file with a pdf extension, if no recordcount returned then just show the file with extension ".doc", but this is asusming you only have one file in the directory, in which case you could just simply list the file no matter what.
0
mosphatCommented:
If I read correctly dmwelter doesn't want to display a link in case the file is a .doc and there already is an equally named pdf file. This should do that trick:

<cfdirectory name="getLinks" directory="d:\inetpub\wwwroot\docs\documents\#passname#\">
<!--- Build list of files for easier searching --->
<cfset listOfFiles = valueList(getLinks.name)>
<cfoutput query="getLinks">
  <!--- Create temp variable with extension of file changed to PDF --->
  <cfset PDFFile = listfirst(getLinks.Name, '.') & ".pdf">
  <!--- If extension is not equal to .doc or if it is and there's no equally named PDF file, display the link --->
  <cfif not (right(name, 4) eq ".doc" and listFindNoCase(listOfFiles, PDFFile))>
    <a href="../documents/#passname#/#getLinks.Name#" target="_blank"">#listfirst(getLinks.Name,'.')#</a><br>
  </cfif>
</cfoutput>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dmwelterAuthor Commented:
That's exactly what I wanted. Thanks mosphat!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.