PDA

Click to See Complete Forum and Search --> : Rename some files


Rotor
Jan 19th, 2000, 06:12 AM
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 / rotor@home.se

MartinLiss
Jan 19th, 2000, 06:23 AM
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

Quizzarex
Jan 19th, 2000, 06:35 AM
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)

ivyl
Jan 19th, 2000, 08:18 PM
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")

ivyl
Jan 19th, 2000, 08:19 PM
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")