Skip to main content
Inspiring
November 20, 2010
Question

Stripping out part of a file name

  • November 20, 2010
  • 2 replies
  • 1172 views

Zip files get uploaded to my server. The zip file has the same name as the folder within it, only with a ".zip" extension of course. There is also an html file within the folder, but not named "quite" the same. Example:

Zip file= "Get_Well_Soon_HTML.zip"

Folder name="Get_Well_Soon_HTML"

File name="Get_Well_Soon.html"

I want to put the name of the html file in my database when the file is uploaded. I can get the folder name easily, since it's the same as the zip file, I just use File.ClientFileName. How can automatically determine the html file's name?

    This topic has been closed for replies.

    2 replies

    commadelimited
    Known Participant
    November 20, 2010

    If your naming conventions are always the same then you could try stripping off the _HTML from the name of the folder, and replace it with .html to get the file name.

    <cfset htmlFileName = ReplaceNoCase(folderName, '_HTML', '.html')

    Squiggy2Author
    Inspiring
    November 20, 2010

    Yep, the replacenocase worked like a dream. Thanks!

    Squiggy2Author
    Inspiring
    November 20, 2010

    Having seen several posts where clientXX variables were used blindly, without understanding what they represent, I just had to ask ...


    I'm pretty rusty with CF, but that's one of the basics I actually do know

    Inspiring
    November 20, 2010

    If you think of the file name as a list delimited by "." you can easily use list functions

    File.ClientFileName

    Is there a reason you are using the ClientXX and not ServerXX variables? Typically you want information about a file's name and location on the server not the client. Depending on the settings you use for cffile, those values are not always the same. Also, FILE is deprecated. Use CFFILE (or cffile's "result" atribute) instead.