473,383 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Just A Simple MKDIR code please.

I been trying to simply make a directory in C++ but I dont get what all these people are talking about and they never put a complete code in there I can use that includes the includes ect. Can you give me a code that will do this simple and straight forward that I can just copy and paste and it will work where all I need to do is change the directory name to what I want it to be please?
Regards and thanks. By the way I did try this and it worked

Expand|Select|Wrap|Line Numbers
  1. #include <direct.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4.  
  5. int main( void )
  6. {
  7.    if( _mkdir( "Directory" ) == 0 )
  8.       printf( "Directory '\\testtmp' was successfully created\n" );
  9.       system( "dir \\testtmp" );
  10.  
  11. }
  12.  
BUT this doesnt seem like its the best way to simply make a directory even though it works. I dont think there should be an if statement needed for one. I just want to break it down to what is actually needed and I need the whole code including includes. Also I am confused to why I need the printf and the system dir testtemp lines.
May 3 '10 #1
2 2363
jkmyoung
2,057 Expert 2GB
Have you tried removing the lines to see if the program still works?

If you succeed in creating your directory what do you want to happen?
What if you fail? Have you considered the error possibilities?

1. File already exists with that name.
2. Permissions errors.
3. Directory already exists.
etc..
May 3 '10 #2
Thanks for the fast response. Well actually I have taken alot of the lines out of the main code already and it seems if I take anything else out I get errors. The main code came from this .

Expand|Select|Wrap|Line Numbers
  1. /* MAKEDIR.C */
  2.  
  3. #include <direct.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6.  
  7. void main( void )
  8. {
  9.    if( _mkdir( "\\testtmp" ) == 0 )
  10.    {
  11.       printf( "Directory '\\testtmp' was successfully created\n" );
  12.       system( "dir \\testtmp" );
  13.       if( _rmdir( "\\testtmp" ) == 0 )
  14.         printf( "Directory '\\testtmp' was successfully removed\n"  );
  15.       else
  16.          printf( "Problem removing directory '\\testtmp'\n" );
  17.    }
  18.    else
  19.       printf( "Problem creating directory '\\testtmp'\n" );
  20. }
I changed void to int which worked and I deleted lines until I got the original code I posted but it seems like there should be a better way like a more direct way less lines of code. Also I dont understand what the line that says ( "dir \\testtmp" ); is for. Thanks Again Appeciate it.
May 3 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: MDJ | last post by:
Hi, haven't been on here for a while but used to help out with ASP queries, hoping for a bit of guidance myself! I've stripped down the code i'm having trouble with to the following, basically I...
1
by: Curious | last post by:
Hi List, Obviously my google-fu is very weak and I can't find a simple sample code for C++ that allows me to simply download the source of a specified web page. I'm looking at downloading the...
8
by: kittykat | last post by:
Hi, could someone please check my code? its asking the user to enter 3 letters, and check to see if these letters exist in the text file. i know ive done something wrong. can someone fix my code...
22
by: Tommy | last post by:
Hi all. I am studying computer security, and I got this short and simple (?) c-code. Something is logical wrong in this code, and if used in the wrong hands of someone, it could be taken advantage...
5
by: Dave Johnson | last post by:
greetings, can any one show sample example of aggregation in any .net code vb.net or C# i guess it shouldnt be that hard but i searched a lot without finding
1
by: shenhaipeng | last post by:
Guys: An ACCESS-newbie is knocking the door ... I am wondering whether it is possible to run a simple SQL code to add an autonumber field from within a Make-Table query. Right now I am...
1
by: disha manikumar | last post by:
Simple java code to read an excel sheet and extract only few fields by treating the excel sheet as a flat file. Can anyone suggest a simple java code for this?
8
by: rocketboy2000 | last post by:
could anyone provide me with some simple example code of asp classic calling adodb? specifically, i'd like the code to: - call a couple of stored procedures that have optional parameters - share a...
2
by: Ecot | last post by:
Hi all, I have not got any php knowledge and I have found a php code on the net and using it to send e-mail from a web html form.So far the form and the code works fine. I have the following php...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.