This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

C program that creates Folder  RSS feed

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need help on how to write a program that creates a folder and inside of that folder is .c file and .h file
 
Sheriff
Posts: 21689
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What did you already find out? And which operating system is it? For instance, on Linux the system calls is mkdir and on Windows it's CreateDirectoryA or CreateDirectoryW (and there actually a few more as well...).
 
David Simic
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something using FILE in c, does not matter which operating system
 
Rob Spoor
Sheriff
Posts: 21689
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

David Simic wrote:does not matter which operating system


Well it does. Creating directories and files are done through system calls which are not the same on all operating systems. My example on the directory creating calls already shows that.
 
David Simic
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Spoor wrote:

David Simic wrote:does not matter which operating system


Well it does. Creating directories and files are done through system calls which are not the same on all operating systems. My example on the directory creating calls already shows that.



Well, in that case use Windows.
 
Saloon Keeper
Posts: 9989
207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case you can include Fileapi.h and use the functions that Rob linked to.
 
David Simic
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your help, i found out another way that works

I will post it here just in case if someone else is looking for a same problem:

 
Stephan van Hulst
Saloon Keeper
Posts: 9989
207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This application is a buffer overflow waiting to happen. What if the file name, directory name or the combination of those two is larger than 25 characters?
 
Ranch Hand
Posts: 116
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Minor point - don't use malloc(); just use something like:
Use snprintf() instead of strcpy() and strcat() to avoid destination array overflow eg.:
and you could(/should) use the snprintf() return value to check for truncation.

And there's a bug:
is equivalent to:
whereas you want:
If you used gcc with -Wall you would get compiler warning 'assignment makes pointer from integer without cast'.
 
Ranch Hand
Posts: 504
Chrome Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My pet peeve are messages like "can't create directory" and "can't create file".  What file/directory can't you create?  The APIs return error codes, use them so I know what the problem is.  For example, "can't create /foo/bar/blatz: permission denied".  Isn't that much more helpful than "Can't create file"?


 
The City calls upon her steadfast protectors. Now for a tiny ad:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!