Web Analytics Made Easy -
StatCounter Stripping Away Path Info - CodingForum

Announcement

Collapse
No announcement yet.

Stripping Away Path Info

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Stripping Away Path Info

    Can someone please point me to a good (easy) tutorial that explains how to strip away path information and leave only a file name. I have found a few very confusing examples and am at a loss as to how to do this.

    Thank You.
    .
    + Christ is the Rock - Rock On!

  • #2
    Don't know of any tutorials but here is a simple way to do it.

    Code:
    <script>
    function extractFileName(fullPath){
    var lastSlashLocation = fullPath.split(/\\|\//);
    var fileName = lastSlashLocation[lastSlashLocation.length-1]
    alert(fileName);
    }
    </script>
    Be sure to pass the fullPath parameter in some kind of event [onclick, onblur, etc.] like this:

    Code:
    <form name="formname" id="formname">
    <input type="file" name="fullpathname" id="fullpathname" />
    <input type="button" value="Get Filename" onclick="extractFileName(document.formname.fullpathname.value);" />
    </form>
    • Jesus called. He says He misses you.

    Comment


    • #3
      Originally posted by Scriptbanger View Post
      Can someone please point me to a good (easy) tutorial that explains how to strip away path information and leave only a file name. I have found a few very confusing examples and am at a loss as to how to do this.

      Thank You.
      Code:
      fileName=path.substring(path.lastIndexOf('/'));

      Comment

      Working...
      X