473,387 Members | 3,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

name = name.substring(0, name.lastIndexOf('.')); Help please

Hi!
Three days ago I wrote in this group for ask help in the use of
"GetDetailsOf".
I want show the name of a file without the extension, and for this, a member
of this group suggestion me that
I will use this code:

name = fldr.GetDetailsOf(items, 0);
name = name.substring(0, name.lastIndexOf('.'));

This code work fine!
But now, I think that this can be a problem of security because hidden all
extension, include .vbs or other possible dangerous type of file.
Somebody can help me and write an example of code for hidden only certain
extension.
I´m not writen a program in JavaScript, but I need used a fragment of code
in this language. The problem is that I don´t know never this language...

Thanks for your help!!

PD: Excuse me for my bad english...
Jul 20 '05 #1
3 7048
VK
To keep it simple, let's avoid regular expressions and use only that you
already know:

var Extensions = "gif,jpg,png";
var NameFull = fldr.GetDetailsOf(items, 0);
var NameOnly = NameFull.substring(0, NameFull.lastIndexOf('.'));
var Ext = NameFull.substring(NameFull.lastIndexOf('.')+1);
if (Extensions.indexOf(Ext) != -1)
{window.alert(NameOnly);}
else
{window.alert(NameFull);}
Jul 20 '05 #2
@SM
Jack-2 a ecrit :

Three days ago I wrote in this group for ask help in the use of
"GetDetailsOf".
I want show the name of a file without the extension,
I will use this code:

name = fldr.GetDetailsOf(items, 0);
don't know what do this fldr.GetDetailsOf(items, 0)
This code work fine!
Somebody can help me and write an example of code
for hidden only certain extension.


function fil(fldr){
nom = fldr.GetDetailsOf(items, 0);
// search extension of file name
sufix = nom.substring((nom.lastIndexOf('\.')+1),(nom.lengt h))
sufix = sufix.toLowerCase();
// give all extensions you want allow (on an alone line)
// indiquer les extensions autorisées (sur 1 seule ligne)
S = 'txt,html,htm,pdf,doc,cwk,rtf,wks,xls,jpg,gif,tif, tiff,png,bmp';
// transform S in an array
S = S.split(',');
// see if extension of file name is ok
ok=0;
for(var i=0;i<S.length;i++)
if(sufix == S[i]) ok=1;
if(ok==0) { // if suffixe not ok
alert('File not allowed');
return
}
alert('All OK');
alert('function add on');
// search file name without extension
nom = nom.substring(0, nom.lastIndexOf('\.'))
alert('main file name = '+nom);
}
Jul 20 '05 #3
Many thanks to all!!

Greetings

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.