View comments | RSS feed
Contents > CFML Reference > ColdFusion Tags > cfdirectory PreviousNext

cfdirectory

Manages interactions with directories.

File management tags

<cfdirectory 
action = "directory action"
directory = "directory name"
name = "query name"
filter = "list filter"
mode = "permission"
sort = "sort specification"
newDirectory = "new directory name">

cffile

ColdFusion MX:

Attribute

Req/Opt

Default

Description

action

Optional

List

  • list: returns a query record set of the files in the specified directory. The directory entries "." (dot) and ".." (dot dot), which represent the current directory and the parent directory, are not returned.
  • create
  • delete
  • rename

directory

Required

 

Absolute pathname of directory against which to perform action.

name

Required if action = "list"

 

Name for output record set.

filter

Optional if action = "list"

 

File extension filter applied to returned names. For example: *.cfm. One filter can be applied.

mode

Optional

 

Used with action = "create". Permissions. Applies only to UNIX and Linux. Octal values of chmod command. Assigned to owner, group, and other, respectively. For example:

  • 644: Assigns read/write permission to owner; read permission to group and other
  • 777: Assigns read/write/execute permission to all

sort

Optional; used if action = "list"

ASC

Query column(s) by which to sort directory listing. Delimited list of columns from query output.

To qualify a column, use:

  • ac: ascending (a to z) sort order
  • desc: descending (z to a) sort order

For example:

sort = "dirname ASC, file2 DESC, size, datelastmodified"

newDirectory

Required if action = "rename"

 

New name for directory

Note: For this tag execute, it must be enabled in the ColdFusion Administrator. For more information, see Configuring and Administering ColdFusion MX.

If you put ColdFusion applications on a server that is used by multiple customers, you must consider the security of files and directories that could be uploaded or otherwise manipulated with this tag by unauthorized users. For more information about securing ColdFusion tags, see Configuring and Administering ColdFusion MX.

If action = "list", cfdirectory returns these result columns, which you can reference in a cfoutput tag:

You can use the following result columns in standard CFML expressions, preceding the result column name with the query name:

#mydirectory.name#
#mydirectory.size#
#mydirectory.type#
#mydirectory.dateLastModified#
#mydirectory.attributes#
#mydirectory.mode# 

Note: If the cfdirectory tag does not appear to work, for example, if a list operation returns an empty result set, make sure that you have correct permissions to access the directory. For example, if you run ColdFusion as a service on Windows, it operates by default as System, and cannot access directories on a remote system or mapped drive; to resolve this issue, do not run ColdFusion using the local system account.

The filter attribute specifies a pattern of one or more characters. All names that match that pattern are included in the list. On Windows systems, pattern matching ignores text case, on UNIX and Linux, pattern matches are case-sensitive.

The following 2 characters have special meaning in the pattern and are called metacharacters:

The following table shows examples of patterns and file names that they match:

Pattern

Matches

foo.*

any file called foo with any extention i.e. foo.html, foo.cfm, foo.xml, ...

*.html

all files with the suffix .html, but not files with the suffix .htm.

??

all files with 2 character names.

<h3>cfdirectory Example</h3>
<!--- use cfdirectory to give the contents of the directory that contains
this page order by name and size ---> <cfdirectory directory="#GetDirectoryFromPath(GetTemplatePath())#" name="myDirectory" sort="name ASC, size DESC"> <!---- Output the contents of the cfdirectory as a cftable -----> <cftable query="myDirectory" htmltable colheaders> <cfcol header="NAME:" text="#Name#"> <cfcol header="SIZE:" text="#Size#"> </cftable>

Contents > CFML Reference > ColdFusion Tags > cfdirectory PreviousNext

ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


zacs said on Aug 12, 2003 at 9:43 PM :
The datelastmodified field can be localised which might require a lsparsedatetime to work with
erkie said on Aug 14, 2003 at 1:45 PM :
cfdirectory action="list" returns dateLastModified as localized datetime value ("teisipäev, 5. August 2003 22:39:48 EEST" for example with Estonian locale on WinXP Pro) even though CF's debugging info says "Locale: English (US)". As it stands, I had to write my own LSParseDateTime like function to convert to CF datetime type :-(
mkbris said on Nov 13, 2003 at 7:02 PM :
erkie - no need to write a LSParseDateTime function - just use the ParseDateTime function. Docs say "Parses a date/time string according to the English (U.S.) locale conventions."
mkbris said on Nov 13, 2003 at 7:06 PM :
Typos in 'sort' attribute description:

* "ac: ascending (a to z) sort order" - should say 'asc' no 'ac'
* not sure if this is a typo but in "sort = "dirname ASC, file2 DESC, size, datelastmodified"" - what are the 'dirname' and 'file2' fields? There not listed as values returned by the 'list' action...
jrunrandy said on Nov 14, 2003 at 7:57 AM :
The sort by should be.
"dirname ASC, name DESC, size, datelastmodified"

file2 should not be part of the example.
grotycom said on Jan 12, 2004 at 2:36 PM :
CFMX 6.1
Windows 2k
Please clarify the 'dirname ASC' sort in the Docs. I assume it will return the folders in the query first, but that does not seem to work.
halL said on Jan 13, 2004 at 7:42 AM :
The use of dirname in the sort example is also incorrect, as it is not a field name from the returned query structure returned by cfdirectory action="list".
The following code results in a quety sorted with directories first:

<cfdirectory action="LIST" directory="C:/temp" name="foo" sort="type, name">
No screen name said on Feb 8, 2004 at 3:00 AM :
How do i list directories Only ? thnxs
halL said on Feb 9, 2004 at 7:39 AM :
To list only directories, you must loop over the query returned by cfdirectory and test the type field.
The following example creates both an array of directory names and a query that contains entries for the directories only.

<cfdirectory directory="C:/temp" name="dirQuery" action="LIST">

<!--- Get an array of directory names. --->
<cfset dirsArray=arraynew(1)>
<cfset i=1>
<cfloop query="dirQuery">
<cfif dirQuery.type IS "dir">
<cfset dirsArray[i]=dirQuery.name>
<cfset i = i + 1>
</cfif>
</cfloop>
<cfdump var="#dirsArray#">
<br>
<!--- Get all directory information in a query of queries.--->
<cfquery dbtype="query" name="dirsOnly">
SELECT * FROM dirQuery
WHERE TYPE='Dir'
</cfquery>
<cfdump var="#dirsOnly#">
No screen name said on Feb 17, 2004 at 2:01 AM :
I use the <cfdirectory action="delete" but if the directory contains files i can not. Is there any solution.
I do not want to list the directory and delete the files one by one. Is time-consuming.
Steve said on Feb 17, 2004 at 8:18 AM :
The way cfml now treats the attributes scope as a regular structure can conflict with the cfdirectory field "attributes". This throws a very nasty error:

<cfdirectory directory="#expandpath(".")#" name="test">
<cfset attributes.hello="world">
<cfloop query="test">
<cfset attributes.hello="moon">
</cfloop>
lbryngel said on Feb 18, 2004 at 1:53 PM :
This note is no longer neccessary in CFMX 6.x. In CFMX, the cfdirectory tag is enabled by default. If the application is in a Security Sandbox it may have the cfdirectory tag disabled but this is not a default setting.

"Note: For this tag execute, it must be enabled in the ColdFusion Administrator. For more information, see Configuring and Administering ColdFusion MX."
lbryngel said on Feb 18, 2004 at 1:32 PM :
We are working to improve the examples in the ColdFusion reference pages. We propose to replace/add the current example on this page with the the following examples. If you have any comments on this example, add them to this page.

<!--- Creating and Renaming Example:
Check that the directory exists to avoid getting a Coldfusion error message. --->
<cfset newDirectory = "otherNewDir">
<cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "newDir">
<!--- Check to see if the Directory exists --->
<cfif DirectoryExists(#currentDirectory#)>
<!--- If TRUE then rename the directory --->
<cfdirectory action = "rename" directory = "#currentDirectory#" newDirectory = "#newDirectory#" >
<cfoutput>
<p>The directory existed and the name has been changed to: #newDirectory#</p>
</cfoutput>
<cfelse>
<!--- If FALSE then create the directory --->
<cfdirectory action = "create" directory = "#currentDirectory#" >
<cfoutput><p>Your directory has been created.</p></cfoutput>
</cfif>

<!--- Deleteing a directory example:
Check that the directory exists and that files are not in the directory
to avoid getting a Coldfusion error messages. --->

<cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "otherNewDir">

<!--- Check to see if the Directory exists --->
<cfif DirectoryExists(#currentDirectory#)>
<!--- If TRUE check to see if there are files in the directory before deleteing --->
<cfdirectory action="list" directory="#currentDirectory#"
name="myDirectory">
<cfif myDirectory.recordcount gt 0>
<!--- If TRUE then delete the files from the directory --->
<cfoutput>
<p>Files exist in this directory either delete the files or code something to do so.</P>
</cfoutput>
<cfelse>
<!--- Directory is empty - just delete the directory --->
<cfdirectory action = "delete" directory = "#currentDirectory#">
<cfoutput>
<p>The directory existed and has been deleted.</P>
</cfoutput>
</cfif>
<cfelse>
<!--- If FALSE then post message or do some other function --->
<cfoutput><p>The directory did NOT exist.</p></cfoutput>
</cfif>
halL said on Feb 18, 2004 at 2:23 PM :
In response to Steve:
There has been a change in behavior between ColdFusion 5 and ColdFusion MX.
This has been submitted as ColdFusion bug number 54319.
Jon Briccetti said on Feb 26, 2004 at 12:26 PM :
looks good, but can you please not use pound signs where you dont need them:
<cfif DirectoryExists(#currentDirectory#)>
SHOULD BE
<cfif DirectoryExists(currentDirectory)>
No screen name said on Mar 3, 2004 at 6:32 PM :
CFDIRECTORY is great ......... but you should implement an algorythm to enable the developer to destroy a directory even if it has files or other directories inside him .........


Today you have to implement some bizarre things like recursive functions .... here go a simple example that i suppose, still have erros and will not work for all ..... but just to begin imagining how an option to destroy entirely the dir (even if it has files or other directories inside him .........) will simplift the developer´s life .....

<cffunction name="recursividadeLama" output="false">
<cfargument name="dir" required="yes">

<cfif url.pasta eq "">
<cfdirectory action="list" name="qryLupi" directory="C:\CFusionMX\wwwroot\#arguments.dir#">
<cfloop query="qryLupi">
<cfif type eq "file">
<cffile action="delete" file="C:\CFusionMX\wwwroot\#arguments.dir#\#name#">
<cfelse>
<cfset recursividadeLama(name)>
</cfif>
</cfloop>
<cfdirectory action="delete" directory="C:\CFusionMX\wwwroot\#arguments.dir#">

<cfelse>
<cfdirectory action="list" name="qryLupi" directory="C:\CFusionMX\wwwroot\#url.pasta#\#arguments.dir#">
<cfloop query="qryLupi">
<cfif type eq "file">
<cffile action="delete" file="C:\CFusionMX\wwwroot\#url.pasta#\#arguments.dir#\#name#">
<cfelse>
<cfset recursividadeLama(name)>
</cfif>
</cfloop>
<cfdirectory action="delete" directory="C:\CFusionMX\wwwroot\#url.pasta#\#arguments.dir#">


</cfif>

</cffunction>
jrunrandy said on Mar 4, 2004 at 7:15 AM :
Have you tried <cfdirectory ... recursive="true">

That should do the trick.
No screen name said on Mar 9, 2004 at 7:44 AM :
When user select one from the dropdown menu, selected pdf file will open. I use following code and getting ODBC Error Code = 08001 (Unable to connect to data source). If you know the solution to this, please let me know.
TIA Kay

<select name="city" >
<cfdirectory action="list" directory="/Download/CityMaps" name="maps" sort="Name ASC">
<cfoutput query="Maps">#name#</cfoutput>
</select>
No screen name said on Mar 18, 2004 at 7:19 AM :
has anyone had any problems using the sort order of CFDIRECTORY. It sorts the file names but not in the exact right order.

for instance, it put all files starting with '@' before files starting with a number. If i look at the directory in windows explorer, the files are in the right order.

Any thoughts????
jrunrandy said on Mar 18, 2004 at 7:41 AM :
LiveDocs does not receive enough traffic to handle questions such as this. I suggest posting your issue to the online forums: http://webforums.macromedia.com/coldfusion/
nathandintenfas s said on Mar 18, 2004 at 10:09 AM :
On March 4th, jrunrandy said:

"Have you tried <cfdirectory ... recursive="true"> ...."

But, CFDIRECTORY has no "RECURSIVE" attribute!
jrunrandy said on Mar 18, 2004 at 10:49 AM :
Oops. My bad. I looked in the wrong source branch.
G0V. said on Mar 29, 2004 at 4:32 AM :
I'm not able to list fiels if my directory is a share on another computer...
(\\computername\shared_directory)
Should I provide credentals and if yes, with what attribute ?
However, the directory i'm willing to access, can be accessed with the windows explorer and is full access for all accounts...
No screen name said on Apr 4, 2004 at 5:53 PM :
Note: If the cfdirectory tag does not appear to work, for example, if a list operation returns an empty result set, make sure that you have correct permissions to access the directory. For example, if you run ColdFusion as a service on Windows, it operates by default as System, and cannot access directories on a remote system or mapped drive; to resolve this issue, do not run ColdFusion using the local system account.
Santa Rosa Mike said on Apr 16, 2004 at 8:47 AM :
Can you go into more detail on not running Cold Fusion on the System Account. I am also trying to access a directory on another server, but I'm rather new to Cold Fusion.
dnimmich said on Apr 25, 2004 at 9:59 AM :
@ 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.)
nk151 said on Jun 7, 2004 at 9:46 AM :
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!).
No screen name said on Jun 30, 2004 at 10:43 PM :
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!!!
No screen name said on Jul 6, 2004 at 9:54 PM :
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?
halL said on Jul 7, 2004 at 8:23 AM :
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.
No screen name said on Jul 11, 2004 at 9:36 PM :
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?
halL said on Jul 12, 2004 at 7:39 AM :
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/.
No screen name said on Jul 12, 2004 at 2:37 PM :
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?
No screen name said on Jul 12, 2004 at 2:49 PM :
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>
_187 said on Jul 19, 2004 at 6:27 AM :
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
hereticmessiah said on Aug 10, 2004 at 11:38 AM :
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.
halL said on Aug 11, 2004 at 11:40 AM :
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>
thewickedone said on Aug 14, 2004 at 5:22 AM :
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","")>
grndvl1 said on Aug 24, 2004 at 8:04 AM :
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?
Ernesto RA said on Sep 3, 2004 at 7:32 AM :
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?
whazaah said on Sep 30, 2004 at 3:22 AM :
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.
dp168 said on Nov 8, 2004 at 12:43 PM :
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?
scrapbox said on Nov 10, 2004 at 4:14 PM :
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.
mindtrap said on Jan 25, 2005 at 11:55 AM :
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?
webdev101 said on Jan 27, 2005 at 3:25 PM :
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#')>
jfine said on Apr 3, 2005 at 3:15 PM :
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.
Pim.Man said on Apr 13, 2005 at 6:27 AM :
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
No screen name said on May 10, 2005 at 1:32 PM :
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.
shobna said on Jun 10, 2005 at 11:31 AM :
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?
jrunrandy said on Jul 5, 2005 at 11:28 AM :
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.
mxstu said on Jul 15, 2005 at 5:19 AM :
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,
mxstu said on Jul 15, 2005 at 9:04 AM :
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.
No screen name said on Sep 7, 2005 at 7:52 AM :
[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">
moneybagsxp said on Oct 4, 2005 at 11:55 AM :
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"
>
No screen name said on Feb 14, 2006 at 10:43 AM :
http://www.easycfm.com/forums/viewmessages.cfm?Forum=12&Topic=8733

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

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/tags-a20.htm