View Full Version : Stripping Away Path Info
Scriptbanger
10-09-2006, 10:49 PM
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.
CrazyCoder
10-10-2006, 01:15 AM
:thumbsup: Don't know of any tutorials but here is a simple way to do it.
<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:
<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>
Arty Effem
10-10-2006, 01:21 AM
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.
fileName=path.substring(path.lastIndexOf('/'));
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.