开发者

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

开发者 https://www.devze.com 2023-03-02 03:47 出处:网络
I know how to get the dir to the folder, but I\'d like开发者_JAVA技巧 to get the name. Thank you for your help.A slightly more efficient method for doing what @Matt Shooks suggests would be to use l

I know how to get the dir to the folder, but I'd like开发者_JAVA技巧 to get the name.

Thank you for your help.


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.


If I read your question right, you are looking for just the current template folder name from the full path to the template. Something like this should work:

<cfset path = ListToArray(GetCurrentTemplatePath(), "\") />
<cfset folderName = path[DecrementValue(ArrayLen(path))] />
<cfoutput>#folderName#</cfoutput>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消