| 1 |
////////////////////////////////////////////////////////////////////////////// |
| 2 |
////////////////////////////////////////////////////////////////////////////// |
| 3 |
// |
| 4 |
// copyright : (C) 2008 by Eran Ifrah |
| 5 |
// file name : dirtraverser.cpp |
| 6 |
// |
| 7 |
// ------------------------------------------------------------------------- |
| 8 |
// A |
| 9 |
// _____ _ _ _ _ |
| 10 |
// / __ \ | | | | (_) | |
| 11 |
// | / \/ ___ __| | ___| | _| |_ ___ |
| 12 |
// | | / _ \ / _ |/ _ \ | | | __/ _ ) |
| 13 |
// | \__/\ (_) | (_| | __/ |___| | || __/ |
| 14 |
// \____/\___/ \__,_|\___\_____/_|\__\___| |
| 15 |
// |
| 16 |
// F i l e |
| 17 |
// |
| 18 |
// This program is free software; you can redistribute it and/or modify |
| 19 |
// it under the terms of the GNU General Public License as published by |
| 20 |
// the Free Software Foundation; either version 2 of the License, or |
| 21 |
// (at your option) any later version. |
| 22 |
// |
| 23 |
////////////////////////////////////////////////////////////////////////////// |
| 24 |
////////////////////////////////////////////////////////////////////////////// |
| 25 |
#include "dirtraverser.h" |
| 26 |
#include "wx/tokenzr.h" |
| 27 |
#include "wx/filename.h" |
| 28 |
#include "wx/log.h" |
| 29 |
#include "fileutils.h" |
| 30 |
|
| 31 |
DirTraverser::DirTraverser(const wxString &filespec, bool includeExtLessFiles) |
| 32 |
: wxDirTraverser() |
| 33 |
, m_filespec(filespec) |
| 34 |
, m_extlessFiles(includeExtLessFiles) |
| 35 |
{ |
| 36 |
m_specArray = wxStringTokenize(filespec, wxT(";"), wxTOKEN_STRTOK); |
| 37 |
} |
| 38 |
|
| 39 |
wxDirTraverseResult DirTraverser::OnFile(const wxString& filename) |
| 40 |
{ |
| 41 |
// add the file to our array |
| 42 |
wxFileName fn(filename); |
| 43 |
|
| 44 |
if(FileUtils::WildMatch(m_filespec, fn)) { |
| 45 |
m_files.Add(filename); |
| 46 |
return wxDIR_CONTINUE; |
| 47 |
} |
| 48 |
|
| 49 |
// if we reached this point, no pattern was suitable for our file |
| 50 |
// test for extensionless file flag |
| 51 |
if (fn.GetExt().IsEmpty() && m_extlessFiles) { |
| 52 |
m_files.Add(filename); |
| 53 |
} |
| 54 |
|
| 55 |
return wxDIR_CONTINUE; |
| 56 |
} |
| 57 |
|
| 58 |
wxDirTraverseResult DirTraverser::OnDir(const wxString &dirname) |
| 59 |
{ |
| 60 |
for (size_t i=0; i<m_excludeDirs.GetCount(); i++) { |
| 61 |
wxString tmpDir(dirname); |
| 62 |
tmpDir.Replace(wxT("\\"), wxT("/")); |
| 63 |
wxArrayString toks = wxStringTokenize(tmpDir, wxT("/"), wxTOKEN_STRTOK); |
| 64 |
wxString dir = m_excludeDirs.Item(i); |
| 65 |
wxString onlyDirName; |
| 66 |
|
| 67 |
if (toks.GetCount() > 0) { |
| 68 |
onlyDirName = toks.Last(); |
| 69 |
} |
| 70 |
|
| 71 |
if (onlyDirName == dir) { |
| 72 |
return wxDIR_IGNORE; |
| 73 |
} |
| 74 |
} |
| 75 |
return wxDIR_CONTINUE; |
| 76 |
} |
| 77 |
|
| 78 |
DirTraverser::~DirTraverser() |
| 79 |
{ |
| 80 |
} |