Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


DirRemove Not Removing Directory

Keywords:  dirremove  

Question:

I am using DirRemove to remove a directory that has files and subdirectories in it, and it won't remove the directory. Is that how it's supposed to work? I don't see anything in the documentation that says the directory has to be empty.

Answer:

DirRemove will only remove an empty directory. You have to nuke the files and subdirectories yourself.

Also note that DirRemove cannot remove a directory that any program is "logged" to (i.e. has open).

So if you have a copy of Windows Explorer looking at a directory, then you cannot DirRemove that directory.

To remove directories containing files, many people just run DelTree (which comes with DOS 6.2+) to do it.

There's also a DELTREE WinBatch script on this website. Search for 'Deltree'.

Our Searcher Extender in its current form may also greatly help in doing this, but it will miss empty directories and zero byte files. Work on fixing these omissions is in progress.

You might also check to see if you have any hidden files in the directory you are trying to delete, or if the directory of files are marked read-only.

Another DirRemove Question:

I'm writing a WB program will first perform a FileDelete on the files within the selected directory. The program will then perform a DirRemove on the directory.

If either the FileDelete or DirRemove fail, the program will throw up a message.

The problem comes in when an error occurs with FileDelete.

If the file is marked read only or another user has it opened and there is a share violation, I capture that error and display a message.

Without exiting the program, I go into DOS or explorer and fix that condition by either marking the file writeable or closing the file if it was opened. Then I attempt to delete the files/directory again. This time, the file DOES get removed by the FileDelete function but the DirRemove function can not delete the directory. Only if I exit out of the WB program and run the same Winbatch script again, am I able to remove the directory.

Any suggestions.

Answer:

There's more than one way to skin a cat.

If you encounter a read-only file, change the file attributes with FileAttrSet, delete the file, and if you still cannot remove the directory, then launch a second copy of the current Winbatch script, and kill off the first one.

Having the first program call itself with the WinExeName function works well. It's quick enough to where it's hard to notice that's what is actually happening. Once the first instance of the program quits, the second one is able to delete the directory.

Be *very* careful when using the errormode function. Only turn it off around isolated code. Something like:

p1="WBT "

errormode(@off)
LastError( )    ;empty out last error buffer
success=DirRemove("C:\TEMP")
errormode(@cancel)
If LastError( ) == 1030
 RunWait(WinExeName(""), "")
 IntControl(47, p1, 0, 0, 0)
Endif

where p1 = the full or partial windowname of a WinBatch program window. This is usually something like, "WBT - C:\Temp\junk.wbt", i.e., "WBT - " followed by the full path to your WBT file.

A partial-winname of "" (null string) in WinExeName specifies the window making the current call to the WIL Interpreter.

Also see IntControl number 12 if it whines.


DirRemove and System Subdirectories Question:

I can't get DirRemove to remove empty subdirectories under the "Temporary Internet Files" directory on NT 4.0 workstations. Any ideas as to why?

Answer:

Under properties for the directory I see that it is marked as a "system" directory. You may want to hit it with a DirAttrSet to change it back to a normal directory. Also make sure you are not logged into the directory before trying to delete it.

Temporary Internet Files are special files that the system caches. Make sure you have your browser closed before you tried to delete any files. And you *might* actually have to go into DOS and delete the files, someone here was saying. Not sure.


Article ID:   W13050
Filename:   DirRemove Not Removing Directory.txt