Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to copy and rename files

Posted on 2002-05-23
12
Medium Priority
?
205 Views
Last Modified: 2010-05-02
Hi

  Could someoen advice me on how i could

        (1). Copy and rename files in VB.
        (2). Rename a folder

Thanx
0
Comment
Question by:b3cf
  • 5
  • 2
  • 2
  • +2
12 Comments
 
LVL 3

Expert Comment

by:SirNick
ID: 7030431
Hi b3cf

Look at the following link to help you copy files.

http://www.freevbcode.com/ShowCode.Asp?ID=499

0
 
LVL 18

Expert Comment

by:bobbit31
ID: 7030433
FileCopy "<source>", "<destination>"
Name "<oldName>" as "<newName>"
0
 
LVL 3

Accepted Solution

by:
SirNick earned 200 total points
ID: 7030436
Look at the following link to help you rename files

http://www.freevbcode.com/ShowCode.Asp?ID=1697

Hope this helps...
0
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.

 
LVL 2

Expert Comment

by:priya_pbk
ID: 7031253
hi b3cf,

You can try this:
----------------------------------------
Open your project and give reference to "Microsoft Scripting Runtime" by going to Projects/References..

Then write this in the code:
---------------------------------------

'Declare file system object
Dim fso As New FileSystemObject

Private Sub Command1_Click()
fso.CopyFile "c:\hello.txt", "c:\helooo.txt", True
fso.CopyFolder "c:\TmpstockIdeaFiles", "c:\TmpstockIdeaFiles2222", True
fso.DeleteFolder "C:\TmpstockIdeaFiles"
End Sub

This will surely work, there are API's too to do this, but I guess the above code accomplishes the same!

-Priya

0
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7031257
also give an "If" condition for both to check if the File exists before copying and Folder exists before renaming so that you dont encounter an error.

Like this:
If fso.FileExists("c:hello.txt") then
   'code for copying the file..as given above
End if

If fso.FolderExists("c:\TmpstockIdeaFiles") then
   'code for renaming the folder
End if

-priya
 
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 7032157
also, if you go with the native vb methods i posted above, you can check whether a file exists by doing:

if dir(<path>) <> "" then file exists
   
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 7245194
hrmm... your question:
Could someoen advice me on how i could

       (1). Copy and rename files in VB.
       (2). Rename a folder

my answer:
1) FileCopy "<source>", "<destination>"
2) Name "<oldName>" as "<newName>"

SirNick's answer (what was in the link):
FileName = "C:\MyFile.txt"
NewFileName = "C:\Text1.txt"
Name FileName As NewFileName

I answered both #1 and #2 and SirNick's #2 is pretty much the same as my #2 and i posted first... that's cool.

0
 

Author Comment

by:b3cf
ID: 7247745
Sorry man,

  I accidently accepted SirNick's answer. How could i change it ?

Thanx
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 7247751
i'll post a question in cs to do it... thanks!
0
 

Author Comment

by:b3cf
ID: 7247759
what is cs ?

Thanx
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 7247762
cs = community support
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7248970
b3cf

Once an answer is accepted, it is accepted. I can't change that anymore. To smooth things out here, I will post a separate question for bobbit31 in this TA.

I hope that helps :-)

** Mindphaser - Community Support Moderator **
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

971 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