Link to home
Start Free TrialLog in
Avatar of xodos
xodos

asked on

rename a file in visual basic

dear sir ,
how can i rename a file in vb6 but with minor changes

i have this code , i renamed the file in it , but there are some errors

Dim izqupdate As String

Private Sub Form_Load()
izqupdate = "c:\abc.izq"
Name izqupdate As izqupdate + ".exe"
End Sub


in this way the file will be renamed to abc.izq.exe ,
i want it to be renamed to abc.exe

i was thinking in this way

name izqupdate as izqupdate - ".izq" + ".exe"
but it didnt work ,
help please
thanks


Avatar of vinnyd79
vinnyd79

Dim izqupdate As String

Private Sub Form_Load()
izqupdate = "c:\abc.izq"
Name izqupdate As Left$(izqupdate, InStrRev(izqupdate, ".") & "exe")
End Sub
First copy the file...
   FileCopy "abc.izq","abc.izq.exe"
then delete the original
   Kill "abc.izq"
here is an explanation of how my comment will work:

InstrRev will find the position of the first "." starting at the back of the string.This position is then used with the Left function to return:

"c:\abc."

Then "exe" will be appended to that so it will result in the file being named:

"c:\abc.exe"
Avatar of xodos

ASKER

i tried this code


Dim izqupdate As String

Private Sub Form_Load()
izqupdate = "c:\abc.izq"
Name izqupdate As Left$(izqupdate, InStrRev(izqupdate, ".") & "exe")
End Sub

and i put the file abc.izq in c:\
but it didnt work
because when i run the project , there was a yellow color highlighted to this code

Name izqupdate As Left$(izqupdate, InStrRev(izqupdate, ".") & "exe")

Name izqupdate & ".izq" as izqupdate & ".exe"

I think the Name routine doesn't recognize the extension if you don't supply it.  we need to see what a possible izqupdate data looks like.
data=string in above statement
if izqupdate = "myfilename" then you should:

Name izqupdate & ".izp" as izqupdate & ".exe"

If izqupdate = "myfilename.izp" then you should:

oldfilename = izuqupdate
newfilename = Left(oldfilename, Instr(oldfilename,".")-1, len(oldfilename)-4) & ".exe"
Name oldfilename as newfilename
Avatar of xodos

ASKER

the extension .izq is nothing  , i named it . and i want to rename it to exe and execute it ,
but i just want to rename it without izq .
which means , my script looks like this
abc.izq.exe , which i want it to look like abc.exe
thanks
Avatar of xodos

ASKER

:D
i think this will help , ,
the lenght command will help ,
but can you please write it in vb language ? thanks
okay.. I goofed.. heres the final code:

change above to:

newfilename = Left(oldfilename, Instr(oldfilename,".")-1) & ".exe"

Okay.. lets try this:

oldfilename = izuqupdate
newfilename = Left(oldfilename, Instr(oldfilename,".")-1) & ".exe"
Name oldfilename as newfilename

what that will do is the following

izuqupdate = "abc.izp"

oldfilename = "abc.izp"
newfilename = "abc.exe"

name oldfilename as newfilename
name "abc.izp" as "abc.exe"

Is this what you wanted??

Then to execute it you would:

shell(newfilename)
ASKER CERTIFIED SOLUTION
Avatar of vinnyd79
vinnyd79

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial