Solved

How to copy and rename files

Posted on 2002-05-23
12
195 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 50 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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now