Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating a folder

Status
Not open for further replies.

leela74

Programmer
May 11, 2001
26
IN
Hi,

How can i create a folder in c. Suppose for eg. from my login id and password I will get the user name the program has to look for the folder in that drive and if it is not there it has to create a folder for that user name.

How do i do this...

Thanks in advance

Sridhar
 
Check out this code:
# include <stdio.h>
# include <string.h>
# include <stdlib.h>

int main()
{
char name[8], command[20]=&quot;md &quot;;

printf(&quot;Enter absolute path for Directory to be created :&quot;);
scanf(&quot;%s&quot;,name);
strcat(command,name);
system(command);
return 1;
}

Here if the directory exists it will be the work of OS to flash appropriate error message.
C,
Less Work, More Utility |-0
Regards,
SwapSawe.
 
Hi, SwapSawe

This program was working but I am getting a message
&quot;The instruction set at &quot;0x72676f72&quot; referenced at 0x72676f72. The memory could not be read.
Click on OK to terminate the application
Click on CANCEL to bebug the application

How to get on with this error....

Thanks in advance

Sridhar
 
Which compiler are you using?
Well try saying # include<dos.h>
Hope it works. :)
 
Your name array is just 8. If you type your path for directory longer then 7 symbols you will have your error.
Maybe easy do:

char command[256];
scanf(&quot;md %s&quot;, command)
system(command);

This will work only on Windows.
 
Whenever u get a memory ref. error it is almost always because of memory allocation problem put malloc wherever req. And as u have told u r using VC++ 6.0 then u have to b specially careful for it is very sensitive to mem alloc probs.
 
change the size of the variable name and command to higher values.

Otherwize user dynamic memory manipulation.
 
change the size of the variable name and command to higher values.

Otherwise user dynamic memory manipulation.
 
SwapSawe,

How do you create that yawning smilie :)

Thanks

abp :cool:
 
Hi,

Is there any possibility to check if the folder exists in a drive.

For eg. in c drive I have a folder c:\abc.

The application should check the existence of abc if it is not there then create a folder if it is there give an error message..

Thanks in advance

Sridhar
 
Hi sridhar,

Pls try to make a folder which already exists OS will take care of giving the error message. However check out errno.h file it will give you details about eexist which generates an error if file already exists.


Regards,
SwapSawe.

Hi abp,
When u post the reply click on preview post and there u'll find a link saying click here to see emoticons and smileys there u'll get all possible symbols.
Use pipe, hyphen and zero like tis but without spaces | - 0
it will give you |-0

SwapSawe.
 
Creating directories is highly system-dependent as is determining if a given directory exists. In POSIX-compliant systems, you'll want mkdir() to create the directory. To find out if a given directory exists, see stat(). Again, this is system-dependent so your compiler may not support these functions but almost definitely has a set of functions that accomplish the same thing.



Russ
bobbitts@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top