likle/cwalk

File path seperator unified?

wrenashe opened this issue · 2 comments

Wonder if you have the API in cwalk, to convert c:\a\b.txt to c:/a/b.txt?

Thanks.

likle commented

Hi @wrenashe, There is no function doing that out of the box - returned windows paths use \ when normalized. I think you could just patch it though:

#include <stdio.h>

static void change_separator(char *path) {
  char *c;
  for(c = path; *c; ++c) {
    if(*c == '\\') {
      *c = '/';
    }
  }
}

int main()
{
    char abc[] = "C:\\a\\b.txt";
    change_separator(abc);
    printf("%s", abc);
    return 0;
}

may I ask why you are trying to do that? just a preference of normal slashes?

Hi likle, yes, I am doing your way now. Thanks for the prompt reply. I like your project here.

The reason to do that, I have an application trying with different scripts, like Tcl, Python, embedded, so trying to "unifying" the file path separator among the platforms. :-)