非常に大きなディレクトリを扱っている場合、cfdirecotry は非常に遅くなります。これは、何千もの画像があるディレクトリがいくつかあるため、私が書いたJavaを使用する関数です。すべてのファイルのクエリ結果を調べて作成し、はるかに高速です
<cffunction name="getDirectorylisting" returntype="query" output="true">
<cfargument name="dirName" type="string" required="true" />
<cfargument name="recurse" type="boolean" default="false" required="false" />
<cfargument name="dirInfo1" type="query" default="#queryNew('datelastmodified,name,size,type,directory,hidden,pathname')#">
<cfscript>
var thisFile = '';
var listFiles = '';
var pathToParse = trim(dirName);
var thisPath = '';
var relPath = '';
var theFileObj = '';
var isDir = '';
var isFile = '';
var thisSize = '';
var lastModified = '';
var isHidden = '';
var theType = '';
if (left(dirName,2) == 'c:' || left(dirName,2) == 'd:' || left(dirName,2) == 'e:' || left(dirName,2) == '\\'){
//do nothing path is already absolute
} else {
pathToParse = expandPath(pathToparse);
}
if(right(pathToParse,1) == '/' || right(pathToParse,1) == '\'){pathToParse = left(pathToParse,len(pathToParse)-1);}
if(right(dirName,1) == '/' || right(dirName,1) == '\'){dirName = left(dirName,len(dirName)-1);}
if (directoryExists(pathToParse)){
listFiles = createObject("java","java.io.File").init(pathToParse).list();
for (thisFile=1;thisFile<=arrayLen(listFiles);thisFile=thisFile+1){
queryAddRow(arguments.dirInfo1);
thispath = "#pathToParse#\#listFiles[thisFile]#";
relpath = "#dirName#/#listFiles[thisFile]#";
theFileObj = createObject("java","java.io.File").init(thispath);
isDir = theFileObj.isDirectory();
isFile = theFileObj.isFile();
thisSize = val(theFileObj.length());
lastModified = theFileObj.lastModified();
isHidden = theFileObj.isHidden();
theType = "dir";
if (isFile){theType = "file";}
querySetCell(arguments.dirInfo1,"datelastmodified", lastModified );
querySetCell(arguments.dirInfo1,"name", listFiles[thisFile] );
querySetCell(arguments.dirInfo1,"size", thisSize );
querySetCell(arguments.dirInfo1,"directory", pathToParse );
querySetCell(arguments.dirInfo1,"hidden", isHidden );
querySetCell(arguments.dirInfo1,"type", theType );
querySetCell(arguments.dirInfo1,"pathName", relPath );
if (arguments.recurse && isDir && !isHidden){
arguments.dirInfo1 = getDirectoryListing(relPath,true, arguments.dirInfo1);
}
}
}
return arguments.dirInfo1;
</cfscript>
</cffunction>