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

J

Jack-2

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...
 
V

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);}
 
@

@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.length))
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) 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);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Code help please 4
I dont get this. Please help me!! 2
Help please 8
Please, help me. 1
Malicious Coding Help Please 5
Can't solve problems! please Help 0
Please Help! 1
Please help me!!! 3

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top