Test for files existing

S

Sandy

Hi,
I have the following code courtesy of this newsgroup; what I would like to
do is check the destination folder to see if there are two files - both
..doc. if so then skip copying them since they are already there from a
previous run.

How do I check the destination folder for these files?
Thanks in advance
Sandy

MyDest = "C:\Users\Sandy\Documents\AAPGA\" _
& inputText & "\Personal Data-" & inputText & "\"

MySource = "C:\Users\Sandy\Documents\Extras\"

fn = Dir(MySource & "*.doc")

Do While fn <> ""
FileCopy MySource & fn, MyDest & fn
fn = Dir()
Loop
 
M

Mike H

Hi,

Maybe you could use something like this

If Dir("full path and filename") <> "" Then
'file exists
Else
'file doesn't exist
End If

Mike
 
S

Sandy

Thing is Mike that there will always be excel files in this folder but only
ever two .doc files (if they are there) - so testing for general files is
not an option.

I would have to test for .doc files.

Sandy
 
R

Ron de Bruin

hi Sandy

With Dir you can test if it exist
Something like this if this is the full path MySource & fn

If Dir(MySource & fn) <> "" then
'Exist
Else
'Not exist
End If
 
S

Sandy

Sorry Mike misread what you suggested.
I will give it a go. I will let you know.
sandy
 
S

Sandy

Hi

Based on your advice the following does the job.
Many thanks to you both

Sandy

********************
MyDest = "C:\Users\Sandy\Documents\AAPGA\" _
& inputText & "\Personal Golf Analyser V2-" & inputText & "\"

MySource = "C:\Users\Sandy\Documents\Extras\"

fn = Dir(MySource & "*.doc")
fn1 = "Paper Record.doc"
fn2 = "ReadMe.doc"

If Dir(MyDest & fn1) <> "" And Dir(MyDest & fn2) <> "" Then

Else

Do While fn <> ""
FileCopy MySource & fn, MyDest & fn
fn = Dir()
Loop

End If
******************************
 

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