For example, I want just the ‘filename’ of a file in a field. Say I have myimage.jpg I only want to display ‘myimage’ How do I get just that?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use the List functions to your advantage.
Be aware that this only works for file names that actually have a file extension (that is defined as the thing after the last dot). To make it safer, the following is better:
To complicate things a bit further: There may be files that start with a dot. There may be file names that contain many adjacent dots. List functions return wrong results for them, as they ignore empty list elements. There may also be files that have dots, but no extension. These can only be handled if you provide an extension white list:
ListFindNoCase(FileExt, 'doc,xls,ppt,jpg'). If you want to account for all of this, you probably need to resign to a reguar expression:To split file name from path, ColdFusion provides distinct functions that also handle platform differences:
GetFileFromPath()andGetDirectoryFromPath()