Using the API to copy files...

I have a small app that copies files using the Win32 API and a timer control.

When the timer event is fired the the app transfers files from location A to location B - however if the folder in location A is empty then the app returns an API error in a MsgBox which just sits there waiting for acknowledgement (as was programmed)

I was wondering if it is possible to test and see if the folder is empty before calling the routine that transfers the files...

Any help would be appreciated
derek_noonanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

crazymanCommented:
if len(dir(YourFolder))<1 then
msgbox "empty"
else
"files found"
end if
0
VbmasterCommented:
Here ya go, a special-designed funtion to see if a directory contains at least one file/dir..

Function IsDirEmpty(ByVal Path As String) As Boolean

  Dim MyName  As String
 
  IsDirEmpty = True
  Path = IIf(Right$(Path, 1) = "\", Path, Path & "\")
  MyName = Dir$(Path & "*.*", vbDirectory + vbArchive + vbHidden + vbReadOnly + vbSystem)
  Do While (Len(MyName) > 0)
    If (MyName <> ".") And (MyName <> "..") Then
      IsDirEmpty = False
      Exit Function
    End If
    MyName = Dir$
  Loop
 
End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VbmasterCommented:
crazyman's code will only check if the folder exist, not if it contains any files/dirs.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

crazymanCommented:
VbMaster if you did my code stating
len(dir(yourDirector,vbDirectory))
then yes it checks if it exists but without the vbdirectory it returns the first file in the dir if there is one or "" if there isnt
0
crazymanCommented:
Opps your right, getting confused,.
0
inprasCommented:
What API UR Using to copy files? this may helps us more to handle that API functionality itself rather than using explicit comparison..
inpras
0
derek_noonanAuthor Commented:
To VBMaster:

Does the Path variable passed to the function need a trailing '\' ?

Respond and the points are yours - this looks damn good!
0
derek_noonanAuthor Commented:
To VBMaster:

Does the Path variable passed to the function need a trailing '\' ?

Respond and the points are yours - this looks damn good!
0
VbmasterCommented:
If the path does not contain a '\' as the last character the line...

  Path = IIf(Right$(Path, 1) = "\", Path, Path & "\")

....will add a '\' to the path string. If you are absolutely sure that you will always send a path with a '\' as the last character you can safely remove that line.

To make the answer short: No.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.