quick coding question..grabbing the filename

Discussion in 'Programming' started by chosenlight, Sep 29, 2008.

  1. #1
    does any1 know how to grab the file name.

    For example :

    I have a db with 2 columns : First Column is names of files, second column is a string. So i want to output that string where the filename of the db is equal to the filename of the cfm file i am working with...

    any help would be appreciated
     
    chosenlight, Sep 29, 2008 IP
  2. CR250

    CR250 Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    There might be a better way but this will work:

    <cfset filename = replace(cgi.SCRIPT_NAME,"/","") />
    <cfdump var="#filename#">
     
    CR250, Sep 29, 2008 IP
  3. chosenlight

    chosenlight Active Member

    Messages:
    363
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #3
    so that would set the variable filename to whatever the file name is.. So if the file name is xyz.cfm, the variable filename is equal to xyz.cfm?? Makes sense, ill give it a try and let you know... Thanks, appreciate it!
     
    chosenlight, Sep 30, 2008 IP
  4. CR250

    CR250 Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yep. Or you could just use this inline: replace(cgi.SCRIPT_NAME,"/","")

    Hope it works for you.
     
    CR250, Sep 30, 2008 IP
  5. chosenlight

    chosenlight Active Member

    Messages:
    363
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #5
    the problem with that is that it gives me the whole file path ie xy/asd.cfm ... i just the name of the file, any suggestions?
     
    chosenlight, Oct 10, 2008 IP
  6. Paul_K

    Paul_K Greenhorn

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #6
    This will work for both linux and windows:

    <cfset filename = listlast(cgi.SCRIPT_NAME,'/\') />
    <cfdump var="#filename#">

    You need the slashes both ways ie windows c:\wwwroot\sitea and linix /var/www/virtual/sitea
     
    Paul_K, Oct 11, 2008 IP
  7. chosenlight

    chosenlight Active Member

    Messages:
    363
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #7
    works like a charm....thank you sir
     
    chosenlight, Oct 12, 2008 IP