Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • Last Modified:

How to copy and rename files

Hi

  Could someoen advice me on how i could

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

Thanx
0
b3cf
Asked:
b3cf
  • 5
  • 2
  • 2
  • +2
1 Solution
 
SirNickCommented:
Hi b3cf

Look at the following link to help you copy files.

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

0
 
bobbit31Commented:
FileCopy "<source>", "<destination>"
Name "<oldName>" as "<newName>"
0
 
SirNickCommented:
Look at the following link to help you rename files

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

Hope this helps...
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
priya_pbkCommented:
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
 
priya_pbkCommented:
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
 
bobbit31Commented:
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
 
bobbit31Commented:
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
 
b3cfAuthor Commented:
Sorry man,

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

Thanx
0
 
bobbit31Commented:
i'll post a question in cs to do it... thanks!
0
 
b3cfAuthor Commented:
what is cs ?

Thanx
0
 
bobbit31Commented:
cs = community support
0
 
MindphaserCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 5
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now