Results 1 to 5 of 5

Thread: Rename some files

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Posts
    1

    Post

    Hello!
    I'm making a demo save utility
    for Action Quake 2 and I would
    like to know how to rename files
    with VB. Like this:
    Original name: demo1.dm2
    The new name : cooldemo1.dm2
    hope you can help / [email protected]

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    From MSDN Help
    =================================
    Name Statement Example
    This example uses the Name statement to rename a file. For purposes of this example, assume that the directories or folders that are specified already exist.

    Dim OldName, NewName
    OldName = "OLDFILE": NewName = "NEWFILE" ' Define file names.
    Name OldName As NewName ' Rename file.

    OldName = "C:\MYDIR\OLDFILE": NewName = "C:\YOURDIR\NEWFILE"
    Name OldName As NewName ' Move and rename file.

    =====================================
    I would change

    Dim OldName, NewName

    to

    Dim OldName as String
    Dim NewName as String

    Better yet would be to also change the names to strOldName and strNewName or sOldName and sNewName.

    ------------------
    Marty

  3. #3
    New Member
    Join Date
    Jan 2000
    Location
    Denmark
    Posts
    4

    Post

    Use the "Filecopy" and "Kill" that is simple.

    Exampel:

    FromBib$ = "c:\q2\aq"
    ToBib$ = "c:\q2\aq"
    FromFil$ = "demo1.dm1"
    ToFil$ = "cooldemo.dm1"
    FromName$ = FromBib$ & FromFil$
    ToName$ = ToBib$ & ToFil$
    If Right$(FromBib$,1) <> "\" Then FromName$ = FromBib$ & "\" & FromFil$
    If Right$(ToBib$,1) <> "\" Then ToName$ = ToBib$ & "\" & ToFil$
    Filecopy FromName$, ToName$
    Kill FromName$

    Simple ) but slowly code (


    ------------------
    Greetings Quizzarex Stargaze )

  4. #4
    Junior Member
    Join Date
    Jan 2000
    Posts
    21

    Post

    One way to do this is to use the API call:

    Declare Function MoveFile Lib "kernel32.dll" Alias "MoveFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String) As Long


    And then use this code (remember to change the directory from C:\ to whatever dir the files are in):

    Dim ret As Long

    ret = MoveFile("c:\demo1.dm2", "c:\cooldemo1.dm2")

  5. #5
    Junior Member
    Join Date
    Jan 2000
    Posts
    21

    Post

    One way to do this is to use the API call:

    Declare Function MoveFile Lib "kernel32.dll" Alias "MoveFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String) As Long


    And then use this code (remember to change the directory from C:\ to whatever dir the files are in):

    Dim ret As Long

    ret = MoveFile("c:\demo1.dm2", "c:\cooldemo1.dm2")

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