1

I have the following c++ code that used to normalize user supplied file path:

wxString orig_path;      
wxFileName res_path(orig_path);
res_path.Normalize(wxPATH_NORM_DOTS);

Refs:

wxFileName::Normalize
wxFileName::Normalize flags

When:

orig_path = "../../dir1/f.csv"

I get annoying error messages:

Error: The path 'f.csv' contains too many ".."!

When:

orig_path = "dir1/../dir2/f.csv"

everything works as expected.

Question

Any way I can suppress those error messages? (silent flag?).
I guess I can do some processing myself before calling Normailze but what's the point? I prefer not to do anything or know anything about orig_path before calling Normailze

Community
  • 1
  • 1
idanshmu
  • 5,061
  • 6
  • 46
  • 92

1 Answers1

4

Use wxLogNull. All calls to the log functions during the life time of an object of this class are just ignored. See documentation.

wxLogNull noLogsPlease;
wxString orig_path;      
wxFileName res_path(orig_path);
res_path.Normalize(wxPATH_NORM_DOTS);
Vikram Singh
  • 1,726
  • 1
  • 13
  • 25
  • by the way, how can I restore logging for the rest of function execution? I guess this object need to be destroyed. – idanshmu Feb 19 '14 at 11:09
  • Put the part inside { }. As soon as you get out of that piece of code, this local object will be destroyed and your logging will be resumed. Check the first example in documentation. – Vikram Singh Feb 19 '14 at 11:11