Cross-platform method of creating a folder/directory?

前端 未结 2 1473
半阙折子戏
半阙折子戏 2021-01-19 20:01

Is there a way to create a folder/directory \"in code\" using C, that is cross-platform? Or will I have to use the preprocessor to state which method to use?

2条回答
  •  鱼传尺愫
    2021-01-19 20:34

    Is there a way to create a folder/directory "in code" using C, that is cross-platform?

    No. The C language and standard library have no concept of directories at all. There are standard library functions, notably fopen(), that consume file names, which concept subsumes paths (and hence directories), but the standard specifies:

    Functions that open additional (nontemporary) files require a file name, which is a string. The rules for composing valid file names are implementation-defined.

    (C2011 7.21.3/8; emphasis added)

    I know that doesn't speak directly to the question, but it's difficult to prove a negative, and especially to do so concisely. I'm emphasizing the point that the language standard doesn't even know that directories exist, prior to assuring you that in particular, it has no support for creating them.

    Or will I have to use the preprocessor to state which method to use?

    That would be a conventional way to proceed. There are several ways in which you could implement the details.

提交回复
热议问题