-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathfilecounter.cpp
70 lines (62 loc) · 1.54 KB
/
filecounter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/////////////////////////////////////////////////////////////////////////////////
// Author: Steven Lamerton
// Copyright: Copyright (C) 2009 Steven Lamerton
// License: GNU GPL 2 (See readme for more info)
/////////////////////////////////////////////////////////////////////////////////
#include "filecounter.h"
#include "path.h"
#include "toucan.h"
#include <wx/dir.h>
#include <wx/log.h>
FileCounter::FileCounter(){
m_Count = 0;
}
void FileCounter::AddPath(const wxString &path){
m_Paths.Add(Path::Normalise(path));
}
void FileCounter::AddPaths(const wxArrayString &paths){
for(unsigned int i = 0; i < paths.Count(); i++){
m_Paths.Add(Path::Normalise(paths.Item(i)));
}
}
long FileCounter::GetCount() const{
return m_Count;
}
//ATTN : Potentially replace some of this with a wxDirTraverser
bool FileCounter::Count(){
for(unsigned int i = 0; i < m_Paths.Count(); i++){
if(wxDirExists(m_Paths.Item(i))){
CountFolder(m_Paths.Item(i));
}
else{
m_Count++;
}
}
return true;
}
bool FileCounter::CountFolder(wxString path){
if(wxGetApp().GetAbort()){
return true;
}
wxGetApp().Yield();
if (path[path.length()-1] != wxFILE_SEP_PATH) {
path += wxFILE_SEP_PATH;
}
wxDir dir(path);
wxString strFilename;
//Suppress warnings about folders we cannot enumerate
wxLogNull null;
bool blDir = dir.GetFirst(&strFilename);
if(blDir){
do {
if(wxDirExists(path + strFilename)){
CountFolder(path + strFilename);
}
else{
m_Count++;
}
}
while(dir.GetNext(&strFilename));
}
return true;
}