1 #include "nsILocalFile.h"
2 #include "nsStringGlue.h"
5 #include "nsIComponentRegistrar.h"
6 #include "nsIComponentManager.h"
7 #include "nsIServiceManager.h"
9 #include "nsISimpleEnumerator.h"
12 PRBool
LoopInDir(nsILocalFile
* file
)
15 nsCOMPtr
<nsISimpleEnumerator
> entries
;
16 rv
= file
->GetDirectoryEntries(getter_AddRefs(entries
));
17 if(NS_FAILED(rv
) || !entries
)
21 while(NS_SUCCEEDED(entries
->HasMoreElements(&hasMore
)) && hasMore
)
23 nsCOMPtr
<nsISupports
> sup
;
24 entries
->GetNext(getter_AddRefs(sup
));
28 nsCOMPtr
<nsILocalFile
> file
= do_QueryInterface(sup
);
33 if(NS_FAILED(file
->GetNativeLeafName(name
)))
37 printf("%s\n", name
.get());
38 rv
= file
->IsDirectory(&isDir
);
41 printf("IsDirectory Failed!!!\n");
47 nsCOMPtr
<nsILocalFile
> lfile
= do_QueryInterface(file
);
56 main(int argc
, char* argv
[])
60 nsCOMPtr
<nsILocalFile
> topDir
;
62 nsCOMPtr
<nsIServiceManager
> servMan
;
63 rv
= NS_InitXPCOM2(getter_AddRefs(servMan
), nsnull
, nsnull
);
64 if (NS_FAILED(rv
)) return -1;
66 if (argc
> 1 && argv
[1] != nsnull
)
68 char* pathStr
= argv
[1];
69 NS_NewNativeLocalFile(nsDependentCString(pathStr
), PR_FALSE
, getter_AddRefs(topDir
));
74 printf("No Top Dir\n");
77 PRInt32 startTime
= PR_IntervalNow();
81 PRInt32 endTime
= PR_IntervalNow();
83 printf("\nTime: %d\n", PR_IntervalToMilliseconds(endTime
- startTime
));
84 } // this scopes the nsCOMPtrs
85 // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
86 rv
= NS_ShutdownXPCOM(nsnull
);
87 NS_ASSERTION(NS_SUCCEEDED(rv
), "NS_ShutdownXPCOM failed");