Instr function problem

Discussion in 'ASP General' started by .Net Sports, Oct 22, 2009.

  1. .Net Sports

    .Net Sports Guest

    If a filename of a file I upload has a space in it, i want to take the
    space out and rename the file on the fly without the space in the
    name. I'm using the instr function to see if there is a space in the
    name. I can explicitly assign oldFileName and newFileName a value and
    it works, but trying to fill the variables with a dynamic filename
    doesnt do anything to the file in the code below, the filename still
    has a space in it:
    '''''''''''''''''''
    filenm = request("filenm")
    dim oldFileName,newFileName,space
    space = instr(filenm," ")

    if space > 0 then
    oldFileName = filenm
    newFileName = replace(filenm," ","")
    Sub reNameFile()
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    fso.MoveFile server.mappath(oldFileName), server.mappath
    (newFileName)
    Set fso = Nothing
    filenm = newFileName
    End Sub
    call reNameFile
    end if

    response.write filenm & "<br><br>"
    end if


    ??????
    NS
     
    .Net Sports, Oct 22, 2009
    #1
    1. Advertising

  2. .Net Sports

    Dan Guest

    ".Net Sports" <> wrote in message
    news:...
    > If a filename of a file I upload has a space in it, i want to take the
    > space out and rename the file on the fly without the space in the
    > name. I'm using the instr function to see if there is a space in the
    > name. I can explicitly assign oldFileName and newFileName a value and
    > it works, but trying to fill the variables with a dynamic filename
    > doesnt do anything to the file in the code below, the filename still
    > has a space in it:
    > '''''''''''''''''''
    > filenm = request("filenm")
    > dim oldFileName,newFileName,space
    > space = instr(filenm," ")
    >
    > if space > 0 then
    > oldFileName = filenm
    > newFileName = replace(filenm," ","")
    > Sub reNameFile()
    > Dim fso
    > Set fso = CreateObject("Scripting.FileSystemObject")
    > fso.MoveFile server.mappath(oldFileName), server.mappath
    > (newFileName)
    > Set fso = Nothing
    > filenm = newFileName
    > End Sub
    > call reNameFile
    > end if
    >
    > response.write filenm & "<br><br>"
    > end if
    >
    >
    > ??????
    > NS


    You can't put a Sub inside an If .. End If block. Also "space" is a function
    name, so you can't use it as a variable name. And you appear to have too
    many "end if" statements. And what happens if any of the folders the file is
    in have spaces (eg. /my files/filename.jpg)? I'm assuming you won't have
    this in your configuration, but it's worth considering as if this can occur
    then you'll be potentially trying to put the file into a folder that doesn't
    exist.


    Sub reNameFile(oldFileName,newFileName)
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    fso.MoveFile server.mappath(oldFileName), server.mappath(newFileName)
    Set fso = Nothing
    End Sub

    dim filenm, spacepos, nfilenm

    filenm = request("filenm")
    spacepos = instr(filenm," ")

    if spacepos > 0 then
    nfilenm = replace(filenm," ","")
    call reNameFile(filenm, nfilenm)
    end if

    response.write nfilenm & "<br><br>"


    --
    Dan
     
    Dan, Oct 23, 2009
    #2
    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. Kathy Burke
    Replies:
    0
    Views:
    424
    Kathy Burke
    Nov 24, 2003
  2. =?Utf-8?B?cm9kY2hhcg==?=

    InStr test

    =?Utf-8?B?cm9kY2hhcg==?=, Nov 7, 2006, in forum: ASP .Net
    Replies:
    12
    Views:
    636
    =?Utf-8?B?cm9kY2hhcg==?=
    Nov 15, 2006
  3. Replies:
    1
    Views:
    3,478
    Victor Bazarov
    Jul 13, 2005
  4. J. Muenchbourg

    InStr, substr, Mid ???

    J. Muenchbourg, Aug 13, 2003, in forum: ASP General
    Replies:
    1
    Views:
    178
  5. OldDog

    Problem with Instr to find a space

    OldDog, Jun 17, 2009, in forum: ASP General
    Replies:
    2
    Views:
    239
    Bob Barrows
    Jun 17, 2009
Loading...

Share This Page