• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 502
  • Last Modified:

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

1 Solution
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.
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))
  *-- Folder not empty

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:
  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))
      *-- Folder not empty
      WAIT WINDOW "Waiting for file(s) deletion" TIME 0.4
  *-- Error in the deletion process
IF DIRECTORY(Addbs(lcDir) + laDirList(lnI, 1))
  *-- Folder still exists...

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now