remove directory under windows8

Hi Experts
 i have been using the following code to empty the folder then delete it thorough program

                              Erase (Addbs(lcDir) + laDirList(lnI, 1) + "\*.*")
                              Rd (Addbs(lcDir) + laDirList(lnI, 1))

I has been working fine on all operating system.

I have a new machine with OS  Windows8 and it crashes when come to remove directory.
and the error says
 The directory is not empty.

Please help

Thanks.
b001Asked:
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.

Giovanni HewardCommented:
What are your results when running the program with elevated privileges?  (e.g. right-click on program, run as administrator.)   If successful, modify the program properties compatibility mode options (select Windows XP SP3, for example.)

After that you could test changing the location of the folder (i.e. %temp%\app\data ) to a location not protected by Windows.
0
pcelbaCommented:
If the folder is not protected then you have to check whether the directory is empty or not when the RD command executes.  Erase just asks OS to delete the files the physical deletion process can be delayed so the RD may fail...

You should test it:
Erase (Addbs(lcDir) + laDirList(lnI, 1) + "\*.*")
IF ADIR(laTempArray, Addbs(lcDir) + laDirList(lnI, 1) + "\*.*", "HS") = 0
  Rd (Addbs(lcDir) + laDirList(lnI, 1))
ELSE
  *-- Folder not empty
ENDIF

You could also check for subfolders existence.
Solution is to wait a few seconds:
WAIT WINDOW "Waiting for file deletion" TIME 2

or create a simple loop with more frequent ADIR calls:
TRY
  Erase (Addbs(lcDir) + laDirList(lnI, 1) + "\*.*")
  LOCAL lnTime
  lnTime = SECONDS()
  DO WHILE SECONDS()-m.lnTime < 5
    IF ADIR(laTempArray, Addbs(lcDir) + laDirList(lnI, 1) + "\*.*", "HS") = 0
      Rd (Addbs(lcDir) + laDirList(lnI, 1))
      EXIT
    ELSE
      *-- Folder not empty
      WAIT WINDOW "Waiting for file(s) deletion" TIME 0.4
    ENDIF
  ENDDO
CATCH
  *-- Error in the deletion process
ENDTRY
IF DIRECTORY(Addbs(lcDir) + laDirList(lnI, 1))
  *-- Folder still exists...
ENDIF

Open in new window

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
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
Windows 8

From novice to tech pro — start learning today.