By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,128 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
@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

P: n/a
Many thanks to all!!

Greetings

Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.