Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Stripping out part of a file name

Explorer ,
Nov 19, 2010 Nov 19, 2010

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?

1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 19, 2010 Nov 19, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 20, 2010 Nov 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')

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 20, 2010 Nov 20, 2010

Ah, I missed the part about "html" being part of the name not extension. Good catch.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 20, 2010 Nov 20, 2010

Yep, the replacenocase worked like a dream. Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 20, 2010 Nov 20, 2010

Just curious. Did you see the comment cffile ClientXX versus ServerXX variables? (I have never used them myself)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 20, 2010 Nov 20, 2010

I did, and I appreciate the information, but it's an old habit that I've never had an issue with. It still works in this instance as well...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 20, 2010 Nov 20, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 20, 2010 Nov 20, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 20, 2010 Nov 20, 2010
LATEST

Ah, okay. Given that the forums are about code problems, when you see something out of the ordinary (ie potentially problematic) it is practically instinct to comment on it 😉

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources