Switch to full style
For C/C++ coders discussions and solutions
Post a reply

Create User Defined Folder[directory] in C++[Turbo C++]

Tue Jul 06, 2010 1:25 pm

i would like the user to input the folder name
then a file will be created by its name too
im using -

cout<<"Enter Foldername";
gets(foldername);

mkric("foldername")

fstream fout;
fstream.open("foldername/foldername",ios::out|ios::app|ios::binary);
fout<<"LOL!!";
fstream.close();

fstream fin;
fstream.open("foldername/foldername",ios::in);
fin.getline(name,size of foldername);
cout<<name;
fstream.close();
....
...
..
.

but i want users to define the filename and folder name!!
i donot want the filename and foldername to be "foldername".

so what should i do??



Re: Create User Defined Folder[directory] in C++[Turbo C++]

Tue Jul 06, 2010 10:42 pm

why don;t you take the folder name from the user and use mkdir function to create this folder.

Re: Create User Defined Folder[directory] in C++[Turbo C++]

Wed Jul 07, 2010 8:49 am

^^
Thank You For Your Prompt Response!

about the code! -

I tried that but when writing a file to that folder its not happening!

Bassically its a Password Program!
heres what exactly i want to do[with some minor codes missing[ie \n's and etc]

fstream fout;

cout<<"ENTER USERNAME";
gets(username);
// its a char type char[51]

"heres the problem"
mkdir("C:\TC\username");

fout.open("C:\TC\username\username",ios::out|ios::app|ios::binary);

// now here i want to make a file whose name is the "username" inside a folder whose name is also the "username".
//and this should be dynamic as in user 1 writes user name as Hello then folder structure should be
//C:\TC\Hello\Hello.whatever! [whatever is the file extention as you know!!]
// an then when user 2 writes username as Good then folder structure should be like
//C:\TC\Good\Good.whatever!

fout<<username;
....
...
..
.

So can you please give me the code for such a program??
any help will be appreciated!! :wave: :gOOd:

Re: Create User Defined Folder[directory] in C++[Turbo C++]

Sun Jul 11, 2010 5:08 pm

I Tried using mkdir();

it does work!!
but i have a problem!!

its like i have 2 char types having same content

char output[] = "C:\\TC\\Library";
char out[]="C:\\TC\\Database";

now when i make a dir by using mkdir(output);
it does get created

but same code mkdir(out);
doesnt create the folder Database!


what is the problem??

i also tried using strcat to conatinate a // and another word to out.!!
but still no success!!!

help me!

Re: Create User Defined Folder[directory] in C++[Turbo C++]

Sun Jul 11, 2010 9:29 pm

what is your operating system, why you don't try c:/tc/Library , i mean using "/"

Re: Create User Defined Folder[directory] in C++[Turbo C++]

Sun Jul 18, 2010 6:55 pm

^^
Somebody told me to per-force use // than / to avoid mistakes done by "/n" or "/t"
also now i have another problem!!

i am able to create a folder initially!
but then the other one is not being creted as the file path being sent is wrong for some reason!!

dunno how to explain it but here's the code -

Code:

char output[] = "C:\\TC\\Student";
char out[] = "C:\\TC\\Database";
char input[] = "C:\\TC\\Student";
char in[] = "C:\\TC\\Database";

fstream userout;
fstream passout;
fstream userin;
fstream passin;

void main()
{
clrscr();
char username[25],password[25],pwd[25],user[25];


cout<<"\n\n\nEnter Username - ";
gets(username);
cout<<"\nEnter Password - ";
gets(password);



{
mkdir(output);
cout<<"\nOld Output - "<<output;

strcat(output,"\\");
strcat(output,username);

mkdir(output);
strcat(output,"\\");
strcat(output,username);

cout<<"\n\nNew output - "<<output;




userout.open(output,ios::out|ios::app|ios::binary);
userout<<username;
userout.close();

}

{
mkdir(out);
strcat(out,"\\");
cout<<"\nOld Out = "<<out;

strcat(out,username);

cout<<"\n Mid1 OUT = "<<out;

mkdir(out);
strcat(out,"\\");

cout<<"\nMid2 Out = "<<out;
strcat(out,password);
cout<<"\nNew Out = "<<out;

passout.open(out,ios::out|ios::app|ios::binary);
passout<<password;
passout.close();

}
getch();
}



it makes the first directory
also writes the file to it

but if you run this program in Borland C++[Windows XP,Vista]
the variable "out" gets vaguely different values somewhat related to the username!!

like if username entered is - Koool
then "out" is oool\kool\kool....

hence the problem!!




Also do you by chnce have the cstring.h Header file?? also if possible windows.h header file??
i need it!!

Thanks in Advanced!!

Post a reply
  Related Posts  to : Create User Defined Folder[directory] in C++[Turbo C++]
 create folder in asp.net     -  
 java code for listing folder contents from remote folder     -  
 static variable defined in function     -  
 turbo c++     -  
 Maximize Turbo C in Vista     -  
 copy folder     -  
 Get all files in folder     -  
 get Folder path and size     -  
 check folder content using asp     -  
 Zipping a Folder in java     -