Results 1 to 2 of 2

Thread: renaming file

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Pilipinas
    Posts
    441

    renaming file

    RENAMING FOLDER:
    Hi I use this code below to rename a file:

    Dim aName As String
    aName = InputBox("Rename file", "Type new file name")

    Dim NewName As String, OldName As String

    NewName = aName 'new
    OldName = Dir1.List(Dir1.ListIndex) & "\" & File1.FileName 'old
    FirstOccurrence = InStrRev(OldName, "\")
    NewName = Left(OldName, FirstOccurrence) & NewName 'overwrite
    Name OldName As NewName 'change
    Dir1.Refresh

    But my problem, is there extension name. Like for example, I am going to rename a file with the extension name of ".doc", what code should I write, if I ever type the" .doc " or not to the new filename, automatically it will save the file wih the extension name of ".doc"
    Help me please??

  2. #2
    Hyperactive Member
    Join Date
    Nov 2003
    Location
    In Front of my computer...
    Posts
    367
    You can do something like this maybe
    ....

    VB Code:
    1. Dim sName as string
    2. dim NewName as string
    3. sName = InputBox("Rename File", "Boo")
    4. If Not InStr(1, sName, ".doc") Then '- If the file doesnt contain .doc
    5. NewName = sName & ".doc" '- Then add it
    6. '// Save NewName...
    7. End If
    Born to help others
    (If I've been helpful then please rate my post. Thanks)

    call me EJ or be slapped!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width