Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

rename a file in visual basic

Posted on 2005-03-02
13
Medium Priority
?
370 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
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Why WooCommerce is one of the majorly favored choices when it comes to having an eCommerce store. This article will acquaint you with some reasons that I believe make it one of the best eCommerce platforms available.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

571 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