Search Tools Links Login

Copy files in directory - Extremely simple!!


Visual Basic 6, or VB Classic

With this code you can copy all files within a directory with a particular extension to another directory. Actually it will give you a progressive listing of a file with a wildcard and then you can do whatever you want with the file. Extremely simple and straightforward. I dont understand why the other codes are so huge. If you find an error or if you would like to comment please leave a messge.

Original Author: El Mariachi

Inputs

Create a button on your form and call it Command1. Then create a folder "c: empo" and cretae a bunch of files in it with , say, a .doc extension or whatever you want. Then create another folder "c: empx" and dont put anything in there.

Code

Private Sub Command1_Click()
Dim fName As String
fName = Dir("c: empo*.doc") ' Retrieve the first entry.
Do While fName <> "" ' Start the loop.
If GetAttr("c: empo" & fName) <> vbDirectory Then 'only files
  FileCopy "c: empo" & fname, "c: empx" & fName 'copies the file
  'Kill "c: empo" & fname 'deletes the original - optional
End If
fName = Dir ' Get next entry.
Loop
End Sub

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 86 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.