问题
I know how to get the dir to the folder, but I'd like to get the name.
Thank you for your help.
回答1:
A slightly more efficient method for doing what @Matt Shooks suggests would be to use list functions directly, rather than to convert to an array (since you only need to reference it once).
fullpath = getDirectoryFromPath(getCurrentTemplatePath())
assuming that you are on Windows, and your fullpath looks something like c:\inetpub\site\dir, you can use this:
thisFolder = listlast(fullpath, "\/")
Remember that all list functions can take a delimiter (optionally) so you can treat any string delimited like this as a list, not just the default comma-delimited lists.
回答2:
If your problem is finding the name of a file or folder inside of a directory, you can use:
<cfdirectory action="LIST" directory="C:\KnownDirectory" name="DirectoryContentsList" />
<ul>
<cfoutput query="DirectoryContentsList">
<cfif DirectoryContentsList.TYPE eq "D">
<li>#DirectoryContentsList.Name#</li>
</cfif>
</cfoutput>
</ul>
This code should list all directories inside the specified directory. I didn't test it, so there could be typos/errors, but it gives you the general idea.
来源:https://stackoverflow.com/questions/5833264/how-to-get-the-name-of-the-current-folder-not-the-dir-to-the-folder