Is there a simple way to create a folder using C ?

  • Thread starter Sky2004
  • Start date
In summary, there are two programming questions being asked, one regarding the size and location of a command prompt window in Visual C++ and the other regarding creating a folder using C. The response is that there is no known way to pre-specify the size and location of the command prompt window, but there is a simple way to create a folder using C on both Unix and Windows systems.
  • #1
Sky2004
2
0
Hi! :frown:
I have 2 programming questions here. Hope you could help me with it.

Q1) Is there a way to pre-specify the size and location of command prompt window that runs along with my application written using Visual C++ ? Be it using C or some batch command?

Q2) Is there a simple way to create a folder using C ?


Thank you,
Yingtian.
 
Computer science news on Phys.org
  • #2
1) not that I'm aware of.

2) #include <sys/types.h>
#include <sys/stat.h>

int mkdir (const char *path, mode_t mode);

- Warren
 
  • #3
Thanks for your reply!

For Q2), the mkdir u suggested seems to work only for unix? I forgot to say that I am using windows xp...so...is there an equivalent simple syntax for it?

Regards,
Yingtian.
 
  • #4
I'm pretty sure mkdir exists on windows as well.

- Warren
 

1. How do I create a folder in C?

To create a folder using C, you can use the mkdir() function from the stdio.h library. This function takes in the name of the new folder as a parameter and creates it in the current directory.

2. Can I specify the location for the new folder?

Yes, you can specify the location for the new folder by providing the full path as the parameter for the mkdir() function. This will create the folder in the specified location instead of the current directory.

3. What happens if the folder already exists?

If the folder already exists, the mkdir() function will return an error. To avoid this, you can use the rmdir() function to first check if the folder exists and then create it only if it doesn't already exist.

4. How can I create a folder with subfolders in C?

To create a folder with subfolders in C, you can use the mkdir() function in a loop to create each subfolder one by one. Alternatively, you can use the mkdir() function with the -p flag to create all the necessary folders in one go.

5. Is there a limit to the length of the folder name in C?

The maximum length of a folder name in C may vary depending on the operating system and file system used. However, a safe limit to follow is 255 characters to ensure compatibility across different systems.

Similar threads

  • Computing and Technology
Replies
12
Views
2K
  • Computing and Technology
Replies
24
Views
7K
  • Programming and Computer Science
Replies
14
Views
2K
  • Programming and Computer Science
Replies
3
Views
665
Replies
9
Views
3K
  • Programming and Computer Science
3
Replies
81
Views
5K
  • Programming and Computer Science
Replies
12
Views
9K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • Programming and Computer Science
Replies
11
Views
1K
  • Programming and Computer Science
Replies
3
Views
4K
Back
Top