Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
KWSys
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Rolf Eike Beer
KWSys
Commits
006fb95f
Commit
006fb95f
authored
18 years ago
by
Ken Martin
Browse files
Options
Downloads
Patches
Plain Diff
ENH: add a higher performance method to get the number of files in a directory
parent
e95a0fff
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Directory.cxx
+59
-0
59 additions, 0 deletions
Directory.cxx
Directory.hxx.in
+6
-0
6 additions, 0 deletions
Directory.hxx.in
with
65 additions
and
0 deletions
Directory.cxx
+
59
−
0
View file @
006fb95f
...
...
@@ -143,6 +143,47 @@ bool Directory::Load(const char* name)
return
_findclose
(
srchHandle
)
!=
-
1
;
}
unsigned
long
Directory
::
GetNumberOfFilesInDirectory
(
const
char
*
name
)
{
#if _MSC_VER < 1300
long
srchHandle
;
#else
intptr_t
srchHandle
;
#endif
char
*
buf
;
size_t
n
=
strlen
(
name
);
if
(
name
[
n
-
1
]
==
'/'
)
{
buf
=
new
char
[
n
+
1
+
1
];
sprintf
(
buf
,
"%s*"
,
name
);
}
else
{
buf
=
new
char
[
n
+
2
+
1
];
sprintf
(
buf
,
"%s/*"
,
name
);
}
struct
_finddata_t
data
;
// data of current file
// Now put them into the file array
srchHandle
=
_findfirst
(
buf
,
&
data
);
delete
[]
buf
;
if
(
srchHandle
==
-
1
)
{
return
0
;
}
// Loop through names
unsigned
long
count
=
0
;
do
{
count
++
;
}
while
(
_findnext
(
srchHandle
,
&
data
)
!=
-
1
);
_findclose
(
srchHandle
);
return
count
;
}
}
// namespace KWSYS_NAMESPACE
#else
...
...
@@ -174,6 +215,24 @@ bool Directory::Load(const char* name)
return
1
;
}
unsigned
long
Directory
::
GetNumberOfFilesInDirectory
(
const
char
*
name
)
{
DIR
*
dir
=
opendir
(
name
);
if
(
!
dir
)
{
return
0
;
}
unsigned
long
count
=
0
;
for
(
dirent
*
d
=
readdir
(
dir
);
d
;
d
=
readdir
(
dir
)
)
{
count
++
;
}
closedir
(
dir
);
return
count
;
}
}
// namespace KWSYS_NAMESPACE
#endif
This diff is collapsed.
Click to expand it.
Directory.hxx.in
+
6
−
0
View file @
006fb95f
...
...
@@ -47,6 +47,12 @@ public:
*/
unsigned long GetNumberOfFiles() const;
/**
* Return the number of files in the specified directory.
* A higher performance static method.
*/
static unsigned long GetNumberOfFilesInDirectory(const char*);
/**
* Return the file at the given index, the indexing is 0 based
*/
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment