?
Solved

rename a file in visual basic

Posted on 2005-03-02
13
Medium Priority
?
369 Views
Last Modified: 2013-12-04
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


0
Comment
Question by:xodos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 3
  • +1
13 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 13440885
Dim izqupdate As String

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

Expert Comment

by:gabeso
ID: 13440893
First copy the file...
   FileCopy "abc.izq","abc.izq.exe"
then delete the original
   Kill "abc.izq"
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 13440960
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"
0
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 

Author Comment

by:xodos
ID: 13441128
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")

0
 
LVL 4

Expert Comment

by:abbdan
ID: 13441576
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.
0
 
LVL 4

Expert Comment

by:abbdan
ID: 13441588
data=string in above statement
0
 
LVL 4

Expert Comment

by:abbdan
ID: 13441640
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
0
 

Author Comment

by:xodos
ID: 13441646
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
0
 

Author Comment

by:xodos
ID: 13441667
:D
i think this will help , ,
the lenght command will help ,
but can you please write it in vb language ? thanks
0
 
LVL 4

Expert Comment

by:abbdan
ID: 13441676
okay.. I goofed.. heres the final code:

change above to:

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

0
 
LVL 4

Expert Comment

by:abbdan
ID: 13441740
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??

0
 
LVL 4

Expert Comment

by:abbdan
ID: 13441767
Then to execute it you would:

shell(newfilename)
0
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 2000 total points
ID: 13441835
Sorry,I had a bracket in the wrong place in my example.It should have been:

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

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question