Find duplicate filenames before copying

B

bhammer

ACC2003
I have a list of source files (Path & Filenames) that I want to copy to a
destination folder (Path). How can I check for duplicates first?
-Brad
 
S

Stuart McCall

bhammer said:
ACC2003
I have a list of source files (Path & Filenames) that I want to copy to a
destination folder (Path). How can I check for duplicates first?
-Brad

Use VBA's built-in Dir function:

Dim d As String

d = Dir("C:\MyFolder\Thing.txt")

'(result if Thing.txt exists: Thing.txt)

If Len(d) > 0 Then
'Duplicate found, Don't do the copy
Else
FileCopy "Thing.txt", "C:\MyFolder\Thing.txt"
End If
 
B

bhammer

Having trouble still . . .

What I have so far is a form with a cmdBrowseSourceFolder button with an
OnClick event that calls the API for the user to browse to the source folder,
then the files are read and stored in tblCatalog_Temp with FileNames of all
the JPG's in the SourceFolder. The source folder path is stored in
Me.txtSourceFolder. Next the user clicks cmdBrowseDestFolder that browses to
the Destination Folder where the JPG's are to be copied. A third button
starts the coping procedure.

I have this working fine, but I need a check for duplicate filenames prior
to copying.

So I need another button, say, cmdCheckForDupes that will compare each of
the filenames in tblCatalog_Temp against each of the filenames in the
destination folder, Me.txtDestFolder. As soon as the first duplicate is
found, I want a msgbox to pop up, informing the user that filenames will have
to be changed before they can be copied. How?

I need to check every filename in the Source folder against every filename
in the Destination folder.

-Brad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top