wxDir::GetAllFiles and dotfiles on Unix

20 views
Skip to first unread message

Kevin McCarty

unread,
Apr 6, 2021, 1:22:12 PM4/6/21
to wx-users

Hi all,

The following code behaves differently on Linux (wxGTK) versus Windows (wxMSW) --

wxString srcDir = ...;
wxArrayString files;
wxDir::GetAllFiles(srcDir, &files, "", wxDIR_FILES);

If there are any dot-files (".foo" or ".vimrc" or similar) in srcDir, wxMSW picks them up but wxGTK does not.  Is this discrepancy intentional?  If so, what is the recommended way to pick up the dot files as well on Linux, too?

Thanks in advance!

Kevin B. McCarty

Vadim Zeitlin

unread,
Apr 6, 2021, 1:23:00 PM4/6/21
to wx-u...@googlegroups.com
On Tue, 6 Apr 2021 10:22:12 -0700 (PDT) Kevin McCarty wrote:

KM> The following code behaves differently on Linux (wxGTK) versus Windows
KM> (wxMSW) --
KM>
KM> wxString srcDir = ...;
KM> wxArrayString files;
KM> wxDir::GetAllFiles(srcDir, &files, "", wxDIR_FILES);
KM>
KM> If there are any dot-files (".foo" or ".vimrc" or similar) in srcDir, wxMSW
KM> picks them up but wxGTK does not. Is this discrepancy intentional? If so,
KM> what is the recommended way to pick up the dot files as well on Linux, too?

You need to add wxDIR_HIDDEN to the flags.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

Kevin McCarty

unread,
Apr 6, 2021, 1:33:46 PM4/6/21
to wx-users
On Tuesday, April 6, 2021 at 10:23:00 AM UTC-7 Vadim Zeitlin wrote:
On Tue, 6 Apr 2021 10:22:12 -0700 (PDT) Kevin McCarty wrote:

KM> The following code behaves differently on Linux (wxGTK) versus Windows
KM> (wxMSW) --
KM>
KM> wxString srcDir = ...;
KM> wxArrayString files;
KM> wxDir::GetAllFiles(srcDir, &files, "", wxDIR_FILES);
KM>
KM> If there are any dot-files (".foo" or ".vimrc" or similar) in srcDir, wxMSW
KM> picks them up but wxGTK does not. Is this discrepancy intentional? If so,
KM> what is the recommended way to pick up the dot files as well on Linux, too?

You need to add wxDIR_HIDDEN to the flags.

Ah, thank you!  I was confused by the wording in the docs that  "Only files matching the filespec are taken, with empty spec matching all the files."  This is 100% true with wxDIR_DEFAULT of course, but for my use case I didn't want to traverse sub-directories.  So I passed in wxDIR_FILES, the only flag value mentioned at GetAllFiles() description besides wxDIR_DIRS and wxDIR_DEFAULT.

I see that wxDIR_HIDDEN is indeed documented at wxDirFlags -- might it be worthwhile to mention at GetAllFiles() also?  (If you think not, no worries.)

Best,
Kevin B. McCarty

Vadim Zeitlin

unread,
Apr 6, 2021, 9:41:49 PM4/6/21
to wx-u...@googlegroups.com
On Tue, 6 Apr 2021 10:33:46 -0700 (PDT) Kevin McCarty wrote:

KM> I see that wxDIR_HIDDEN is indeed documented at wxDirFlags -- might it be
KM> worthwhile to mention at GetAllFiles() also?

Sure, I've done this in a957d29f8c (Mention wxDIR_HIDDEN in GetAllFiles()
documentation, 2021-04-06) now. Please don't hesitate to submit PRs with
docs correction if you see anything else to improve!
Reply all
Reply to author
Forward
0 new messages