How to get the name of the current folder, not the dir to the folder

 ̄綄美尐妖づ 提交于 2019-12-23 04:48:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!