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]
Printable View
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]
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
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 :o) but slowly code :o(
------------------
Greetings Quizzarex Stargaze :o)
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")
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")