CountDirectories() Fails on Novell NetWare Server Drive

ID: Q122309

The information in this article applies to:

SYMPTOMS

The Microsoft WordBasic CountDirectories() function does not include subdirectories in empty directories on a Novell NetWare server drive. Consider the following directory structure:

   F:\DOCS
   F:\DOCS\1995
   F:\DOCS\Plan

If the current directory is F:\DOCS, the CountDirectories() function should return 2 in order to indicate that there are two directories in the DOCS directory. However, if the DOCS directory doesn't contain any files, the CountDirectories() function returns zero (0) when the current drive is a Novell NetWare server drive.

WORKAROUND

The following WordBasic function uses Windows API calls to determine how many directories stem from the current directory.

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Declare Function GetModuleHandle Lib "kernel"(lpModuleName$) As Integer
Declare Function GetActiveWindow Lib "User" As Integer
Declare Function CreateWindow Lib "User"(lpClassname$, lpWindowName$, \ 
 dwStyle As Long, X As Integer, Y As  Integer, nWidth As Integer, \ 
 Height As Integer, hWndParent As Integer, hMenu As Integer, hInstance \ 
 As Integer, lpParam$) As Integer
Declare Sub DestroyWindow Lib "User"(hWnd As Integer)
Declare Function SendMsgString Lib "user"(hWnd As Integer, wMsg As \ 
Integer, wParam As Integer, lParam$) Alias "SendMessage" As Integer
Declare Function SendMsgVal Lib "user"(hWnd As Integer, wMsg As \ 
 Integer, wParam As Integer, lParam As Long) Alias  "SendMessage" \ 
 As Integer

Sub MAIN
a$=Files$(".")                         ' stores current directory in a$
chdir "F:\DOCS\Plan"                   ' specify your parent directory here
MsgBox "Directories = " + Str$(GetDirs)
chdir a$                               ' changes path to stored directory
End Sub

Function GetDirs

Dirs = CountDirectories() If Dirs = 0 Then '*** only if countdirs returns 0 LB_RESETCONTENT = 1029 LB_DIR = 1038

DirList = CreateWindow("ListBox", "", 1073741954, 0, 0, 0, 0, \

 GetActiveWindow, 0, GetModuleHandle("winword"), "")

r = SendMsgVal(DirList, LB_RESETCONTENT, 0, 0) Dirs = SendMsgString(DirList, LB_DIR, 16 - 32768, "*.*") If Dirs = - 1 Then
   MsgBox "LB_DIR Error"'shouldn't get this
   Goto bye :
End If

If InStr(DefaultDir$(14), "\") <> 0 And Len(DefaultDir$(14)) < 4 Then

 Dirs = Dirs + 1
End If

DestroyWindow DirList bye: End If GetDirs = Dirs End Function

REFERENCES

"Microsoft Word Developer's Kit," version 6.0, pages 128-130

Kbcategory: kbusage kbmacro KBSubcategory: kbmacroexample Additional reference words: 6.0 6.0a 6.0c winword Subdirectory word6 directory CountDirectories novell empty files network

Keywords          : kbmacroexample 
Version           : 6.0 6.0a 6.0c
Platform          : WINDOWS

Last Reviewed: August 6, 1997