<CFDIRECTORY> Tag - ColdFusion


>> Return to CF Tag List

The <CFDIRECTORY> tag allows you ...




  <CFDIRECTORY> Comments from Macromedia LiveDocsLiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
http://www.easycfm.com/forums/viewmessages.cfm?Forum=12&Topic=8733

For those of you that cannot create directories on remote servers. Very helpful.

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
Yep, you nailed it.
For a directory containing .PDF, .HTML, and .TXT, the below DOES NOT include .PDF, but does .HTML and .TXT

<cfdirectory
action="list"
directory="#CGI.document_root##APPLICATION.absPath#/reports/"
name="pdfFiles"
filter="*.html|*.txt"
sort = "datelastmodified"
>

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
[quote] How can I define more than 1 filter in cfdirectory? I need to filter several filetypes, *.xls, *.doc, *.htm and others. Will this statement work? FILTER="*.*" Any other ideas? [/quote]

<cfdirectory action="list" directory="c:\temp" filter="*.xls|*.doc|*.htm" name="TXTXLSList">

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
Apparently "Size" is a reserved word for queries http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/express4.htm

Even though CFDIRECTORY returns a column named "Size" it doesn't seem like you can include the column by name in a Q of Q.

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
I tried the multiple filter code suggested by No Screen Name, and it worked fine until I tried to specify the column names. The Q of Q UNION worked fine until I included the "Size" column.

<cfdirectory action="list" directory="c:\temp" filter="*.txt" name="TXTList">
<cfdirectory action="list" directory="c:\temp" filter="*.xls" name="XLSList">

<cfdump var="#TXTList#">

<cfquery dbtype="query" name="NewQuery">
SELECT Attributes, DateLastModified, Mode, Name, Type, Size
FROM TXTList
UNION
SELECT Attributes, DateLastModified, Mode, Name, Type, Size
FROM XLSList
ORDER BY NAME
</cfquery>

Returns error

Error Executing Database Query.

Query Of Queries syntax error.
Encountered "Size" at line 0, column 0. Incorrect Select List, Incorrect select column,

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
Shobna. I'm sorry. I can't think of a workaround for this. You might try posting your question to the online forums. http://webforums.macromedia.com/coldfusion. One of the people who monitor the forums may have a creative workaround.

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
If cfdirectory tag is turned off in the cf administrator (because of security issues), how do I get the names of the files I need to retrieve for my application?

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
For those looking to filter multiple file types, try this:
<cfdirectory action="list" directory="#your_dir# filter=".jpg" name="JPGList">
<cfdirectory action="list" directory="#your_dir# filter=".gif" name="GIFList">
<cfquery dbtype="query" name="MyList">
SELECT * FROM JPGList
UNION
SELECT * FROM GIFList
ORDER BY NAME
</cfquery>

That should work.

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
I have a better redundancy solution ;) (at least on Windows)
<cfobject type="COM" action="create" class="Scripting.FileSystemObject" name="myFso">
<cfset folder = myFso.GetFolder("myDir")>
<cfset folder.Delete() >

Cheers
/pim

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
Found a strange but very handy way to move a folder, subfolders, and all files within the folder. Using cffile, not cfdirectory, and using a folder name as source:

<cffile action = "move"
source = "#foldername#"
destination = "#destname">

At least on windows2003, it moves the folder and everything in it. Good for me, hope that doesn't change.

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
since the function to destroy a directory even if it contains files and folders posted priously, had some hardcoded and redundant stuff, i had to code my own: hope it helps someone:

<cffunction name="dirDelete" access="public" output="false" returntype="any">
<cfargument name="dir" required="no" default="#expandPath('/pocket_cache/')#">
<cfdirectory action="list" name="delfile" directory="#arguments.dir#">
<cfif delfile.RecordCount EQ 0>
<cfif directoryExists(arguments.dir)>
<cfdirectory action="delete" directory="#arguments.dir#">
</cfif>
<cfelse>
<cfloop query="delfile">
<cfif type EQ "file">
<cffile action="delete" file="#arguments.dir#\#name#">
<cfelse>
<cfset temp = dirDelete(arguments.dir & '\' & #delfile.name#)>
</cfif>
</cfloop>
<cfif directoryExists(arguments.dir)>
<cfdirectory action="delete" directory="#arguments.dir#">
</cfif>
</cfif>
</cffunction>

USE
<cfset dirDelete('#FULL PATH#')>

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
I ran into a major problem lately where <CFDIRECTORY> returns the following value in the column: datelastmodified = 'January 25, 2005 2:28:57 o'clock PM EST'.

First of all where the heck does the "o'clock' come from and why does IsDate return Yes, but all other date functions fail on this data?

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
Ive been working with cfDirectory and in addition to the problem with modified dates, I've have noticed the filter behavior has changed.

In coldfusion 5 i was using cfDirectory with filter="*." to list only the directories, like this...

<cfdirectory action="LIST" directory="#thisPath#" name="dirsOnly" filter="*.">

<cfloop query="dirsOnly">
[blah]
</cfloop>

That worked great in 5 but in MX it returns an empty record set.

Now i have list everything and check the type when im looping through it, like this right?...

<cfdirectory action="LIST" directory="#thisPath#" name="filesAndDirs">

<cfloop query="filesAndDirs">
<cfif type eq "dir">
[blah]
</cfif>
</cfloop>

Its a lot slower now because most of the directories im dealing with here have maybe hundreds of files but only few directories. Being able to filter out all the files and just deal with the dirs was substantially faster. It'd be great if that functionality returned some day.

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
When I use cfdirectory to return the server file time stamp, datelastmodified is returning an adjusted time to account for DST. Is there a way to return the time as is?

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
Is there someone who nows if you can limit the resultset of a cfdirectory (list)? I need just 1000 files of a directory with about 100000 files in it. It slows down the process very hard to list all 100000 with the cfdirectory tag and then loop over the first 1000 of it.

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
The ? character in the file parameter didn't seems to work. When I tried to use it, CF throws a "Error: ?+* follows nothing in expression null". It seems that it's taking the filter parameter as a regular expression?

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
Just a quick question. When I am using CFdirectory the application is running in c:/wwwroot/application/hthml. I need CFdirectory to look at a root folder on the webserver C:/wwwroot/images/home. I am testing on a windows server but the problem comes when I go to deploy this live on a Linux server. Since the directory requires absolute path how do I do this dynamically?

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
since the function to destroy a directory even if it contains files and folders posted priously, threw me some errors, i had to code my own: hope it helps someone:

<cffunction name="deldirtree" output="false">
<cfargument name="dir" required="yes">
<cfargument name="sdir" required="no" default="">
<cfset ndir="">
<cfdirectory action="list"
name="delfile"
directory="C:\CFusionMX\wwwroot\#arguments.dir##arguments.sdir#">
<cfif arguments.sdir EQ ""
AND delfile.RecordCount EQ 0>
<cfset dirtodel = "C:\CFusionMX\wwwroot\#arguments.dir#">
<cfif DirectoryExists(dirtodel)>
<cfdirectory action="delete"
directory="#dirtodel#">
</cfif>
<cfelse>
<cfloop query="delfile">
<cfif type EQ "file">
<cffile action="delete"
file="C:\CFusionMX\wwwroot\#arguments.dir##arguments.sdir#\#name#">
<cfelse>
<cfset ndir = sdir & "\#name#">
</cfif>
</cfloop>
<cfif ndir NEQ "">
<cfset deldirtree(arguments.dir,ndir)>
<cfelse>
<cfset dirtodel = "C:\CFusionMX\wwwroot\#arguments.dir##arguments.sdir#">
<cfif DirectoryExists(dirtodel)>
<cfdirectory action="delete"
directory="#dirtodel#">
</cfif>
<cfset i = 1>
<cfloop condition = "i LT Len(arguments.sdir)">
<cfif Find("\",arguments.sdir,i) GT 0>
<cfset i = Find("\",arguments.sdir,i) + 1>
<cfelse>
<cfset j = i - 2>
<cfset i = Len(arguments.sdir)>
</cfif>
</cfloop>
<cfif j EQ 0>
<cfset deldirtree(arguments.dir,"")>
<cfelse>
<cfset deldirtree(arguments.dir,"#Left(arguments.sdir,j)#")>
</cfif>
</cfif>
</cfif>
</cffunction>
<cfset deldirtree("Folder to delete","")>

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
In respose to hereticmessia:
This issue should be resolved in the next major release of ColdFusion MX.
In the meantime, you could try the following custom function in place of LSParseDateTime to workaround the issue:

<cffunction name="custom_lsparsedatetime" return="date">
<cfargument name="str" required="yes">
<cfobject type="java" class="java.text.DateFormat" action="create" name="df">
<cfset fulldf = df.getDateTimeInstance(df.FULL, df.FULL)>
<cfreturn fulldf.parse(str)>
</cffunction>

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
Consider this, kids:

You're a developer sitting in some country whose locale isn't on JRun's list. For the most part, this is fine: you deal with dates in UTC or, if it doesn't matter, without caring what the timezone is.

Then you try and list a directory using CFDIRECTORY and assume that the dates you get from that are *real* date objects (i.e. {ts 'blah blah'}). To your surprise, they're not, but are ones formatted for the current locale.

No problem, you think, I'll just run this through LSParseDateTime(). But no joy: you're told it's not a valid date.

Then you try plain old ParseDateTime(), but *that* tells you that it doesn't support the en_IE (I'm in Ireland) locale. Now, this beggars belief.

So, what's a lad to do: he's working with a tag the spits back dates in an obviously flawed format and parsing functions unable to parse dates produced by another part of the product.

And no, switching from IST to BST isn't an option. I've tried that and the blasted thing is *still* spitting back bad dates. Right now, I'd like to clobber the programmer who wrote this code with a very big stick.

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
I need the cfdirectory function returning the files ordered by file name but case insensitive. Is it possible just with the cfdirectory tag ?
I'm under CF 5.0 Linux
Thx

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
My bad. I was so used to cf 5.0 I was using startrow in the cfoutput to eliminate . and ..
Sorry.


<cfdirectory action="LIST" name="getImgz" directory="#uImageFile#" sort="name ">
......
<cfoutput query="getImgz" startrow="3">
<option value="#name#">#name#
</cfoutput>

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
When attempting to use the list function in cfdirectory (in CFMX 6.1) with NO directory filter, the list does not contain either the first 2 files in the directory when sort = "name asc" or the last two files when sort="name desc". This also happens when no sort is applied (see sort-"name asc")

Is this a known bug? Is there a HotFix?

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
The behavior depends on the operating system and how it resolves the path and determines permissions.
I believe the issue is that when you use the mapped drive, Windows uses the wide-open permissions.
When you use the IP address, you are probably short-circuiting the Windows sharing mechanism and its permission settings.
For further information, I suggest posting your issue to the online forums: http://webforums.macromedia.com/coldfusion/.

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
Thank you "halL said on Jul 7, 2004 at 8:23 AM ".

After changing the ColdFusion MX service to have higher permissions the IP address started to work. (Not really what I wanted though due to security concerns)

However, my initial testing with the service configured with "Local System" I got the following results:

I setup a share with share permissions Everyone Full Control and NTFS permissions Everyone Full Control. There were two text files in the share inheriting the same permissions.

I wasn't able to display the directory list using the IP address to connect.

I was able to display the directory list using a name to connect (I added the name and IP address to the local hosts file for name resolution).

Can someone verify this behaviour?

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
In response to No Screen Name of July 6 2004:
You can use an IP address, as in the following example:

<cfdirectory directory="//12.3.123.123/c_drive/" name="dirQuery" action="LIST">
<cfdump var="#dirQuery#">


Remember that ColdFusion must be running in a process with remote access permissions.
By default, if you run ColdFusion MX as a service in Windows, it runs under the local system account which lacks such permissions, as described in the note on this page.

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
cfdirectory in MX 6.1 doesn't support using an IP Address for a remote directory: "\\[IP Address]\Share\Directory"
eg \\123.123.123.123\myshare\mydirectory
This used to work in ColdFusion 5. I haven't been able to find any documents that list this as a change yet. Can someone confirm this?

How are names resolved by the cfdirectory tag for remote computers?

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
How can I define more than 1 filter in cfdirectory? I need to filter several filetypes, *.xls, *.doc, *.htm and others. Will this statement work? FILTER="*.*" Any other ideas? I need to resolve this for work so ANY prompt response is GREATLY appreciated!!!

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
On Windows, with MX 6.1, a call to CFDIRECTORY without an absolute path will create directories under the CFusionMX\runtime\bin directory, not the directory of the current template (just in case you're wondering where it went!).

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-a20.htm
@ Santa Rosa Mike: This is not really a ColdFusion related problem but a Windows thing. You need to change the properties of the ColdFusion service, to be more precise: the account the ColdFusion MX Application service runs with. Unfortunately, Microsoft changes the way how to do this in every new Windows version and I only have a German one (which likely doesn't help you), so it is probably the best if you ask your local Windows guru how to run a service with a different user account. (And don't forget to tell him what Windows version you are running.)



[Top]


Recommended Books

[Top]

Web Sites

[Top]

Copyright © 2003- 2008, Orville Paul Chomer, All Rights Reserved