The File object supports the IADsContainer interface.
The Count property is not implemented for File objects.
You can use the IADsContainer to create and delete objects like files, directories, and shares.
Note that only members of the Administrators or Account Operators local group or those with Communication, Print, or Server Operator group membership can do file share management. This includes creating and deleting file shares, viewing and changing file share properties and changing permissions on file shares.
You can enumerate the contents of a File container using the "For Each" construct of Visual Basic. Enumeration is possible only for directories and at the top level when bound to "file_services". An IADsContainer for a File object contains objects of type IFile.
While enumerating objects in a directory, you can use either of the following five types of Filters. Possible values of Filter are:
Complete tree |
Recursive enumeration of all files and directories |
Nextlevel file and directory |
Non recursive enumeration of files and directories |
Nextlevel directory |
Non recursive enumeration of directories |
Nextlevel file |
Non recursive enumeration of files |
Share |
Enumerates all shares when bound to "file_services". |
A quick example:
Dim FileContainer As IADsContainer
Dim File As IFile
'Get the IADsContainer interface for the documents directory
Set FileContainer =
GetObject("NTDS://<DomainName>/<MachineName>/file_services/<Share
Name>/<Folder Name>")
'Enumerate only files in the current directory
FileContainer.Filter = "Nextlevel file"
For Each File in FileContainer
Debug.Print File.RelativePath
Next File
'Get the IADsContainer interface for the top level
Set FileContainer =
GetObject("NTDS://<DomainName>/<MachineName>/file_services")
'Enumerate the shares on the computer. Since this filter is the
default at the top level, this step is optional
FileContainer.Filter = "Share"
For Each File in FileContainer
Debug.Print File.Name, File.Class
Next File
See Also