PDA

View Full Version : How to get the file separator



cl333r
May 26th, 2009, 09:54 PM
Hi,
Is it possible to get it through glib or Gtk? (or glibmm & gtkmm)

For example in Java I have java.io.File.separator which is "/" in Linux and "\" in windows.

crdlb
May 26th, 2009, 11:01 PM
G_DIR_SEPARATOR or (G_DIR_SEPARATOR_S for a string version), but g_build_filename should be used whenever possible.

cl333r
May 26th, 2009, 11:49 PM
Thanks! works indeed:



Glib::ustring sep = G_DIR_SEPARATOR_S;
cout << "separator: " << sep << endl;




separator: /

DocForbin
May 27th, 2009, 01:51 AM
Just curious, but is it not safe to always use / these days? I know it works fine on XP+ windows.

crdlb
May 27th, 2009, 02:19 AM
Just curious, but is it not safe to always use / these days? I know it works fine on XP+ windows.

I still use g_build_filename because it feels cleaner and more correct: it makes the code more self-documenting and makes it possible to support a future platform GLib adds support for. It also prevents situations where you might forget or duplicate the separator when concatenating two parts.

soltanis
May 27th, 2009, 04:39 AM
It also prevents situations where you might forget or duplicate the separator when concatenating two parts.

Also prevents situations where Microsoft changes this compatibility for the sole purpose of screwing you up. Oh, you know they'd do it.