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

Discussion in 'Javascript' started by Jack-2, Dec 22, 2003.

  1. Jack-2

    Jack-2 Guest

    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...
    Jack-2, Dec 22, 2003
    #1
    1. Advertising

  2. Jack-2

    VK Guest

    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);}
    VK, Dec 22, 2003
    #2
    1. Advertising

  3. Jack-2

    @SM Guest

    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);
    }
    @SM, Dec 23, 2003
    #3
  4. Jack-2

    Jack-2 Guest

    Many thanks to all!!

    Greetings
    Jack-2, Dec 24, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. .Net Sports

    IndexOf and LastIndexOf not working

    .Net Sports, Jan 18, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    3,806
    .Net Sports
    Jan 18, 2006
  2. ccshine via DotNetMonster.com

    Comparing Structure Objects w/ LastIndexOf

    ccshine via DotNetMonster.com, Oct 26, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    334
    ccshine via DotNetMonster.com
    Oct 26, 2006
  3. =?Utf-8?B?dmluYXk=?=

    LastIndexOf

    =?Utf-8?B?dmluYXk=?=, Feb 7, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    481
    =?utf-8?B?5bC55L+K?=
    Feb 7, 2007
  4. Matt
    Replies:
    1
    Views:
    232
    Michael Winter
    Sep 25, 2004
  5. Replies:
    3
    Views:
    200
    Sherm Pendley
    Aug 3, 2005
Loading...

Share This Page