Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8140929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:19:45+00:00 2026-06-06T12:19:45+00:00

In my C++ project I have provided an option to take a backup of

  • 0

In my C++ project I have provided an option to take a backup of the files that are created to store the records, which takes the backup of files in a user given path by creating a folder in that Directory. The code for the same is as follows:

void backup()
{
 char a[40],c[40],b[40];
 product p1;
 clrscr();
 ifstream fp1("products.dat", ios::binary);
 ifstream fp2("purchase.dat",ios::binary);
 ifstream fp3("sales.dat",ios::binary);
 if(fp1==NULL || fp2==NULL || fp3==NULL)
 {
  cout<<"\n\tError-No or Incomplete Database...";
 }
 else
 {
  cout<<d_line;
  cout<<"\t\t\t       Database backup";
  cout<<"\n\t\t\t       -------- ------";
  cout<<line;
  cout<<"\n\tEnter the Directory in which you want to create backup:";
  gets(a);
  strcpy(b,a);
  strcpy(c,a);
  strcat(a,"/backup_b");
  strcat(b,"/backup_b");
  strcat(c,"/backup_b");
  mkdir(a);
  strcat(a,"/products.dat");
  strcat(b,"/purchase.dat");
  strcat(c,"/sales.dat");
  ofstream fp1_t(a, ios::binary | ios::trunc);
  ofstream fp2_t(b, ios::binary | ios::trunc);
  ofstream fp3_t(c, ios::binary | ios::trunc);

  if(fp1_t==NULL || fp2_t==NULL ||fp3_t==NULL)
  {
   cout<<"\n\n\tError During creating backup...\n";
  }
  else
  {
   while(!fp1.eof())
   {
    fp1.read((char *) &p1,sizeof(struct product));
    if(fp1.fail())
    {
     break;
    }
    else
    {
     fp1_t.write((char *) &p1,sizeof(struct product));
    }
   }
   while(!fp2.eof())
   {
    fp2.read((char *) &p1,sizeof(struct product));
    if(fp2.fail())
    {
     break;
    }
    else
    {
     fp2_t.write((char *) &p1,sizeof(struct product));
    }
   }
   while(!fp3.eof())
   {
    fp3.read((char *) &p1,sizeof(struct product));
    if(fp3.fail())
    {
     break;
    }
    else
    {
     fp3_t.write((char *) &p1,sizeof(struct product));
    }
   }
   fp1_t.close();
   fp2_t.close();
   fp3_t.close();
  }
  fp1.close();
  fp2.close();
  fp3.close();
  cout<<line;
  cout<<"\n\tBackup Created Successfully...";
 }
 cout<<line<<conti;
 getch();
}

I want to know, is there a more efficient way to create a folder in C++ than what I am doing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:19:48+00:00Added an answer on June 6, 2026 at 12:19 pm

    Well there are certainly more platform-independent ways of doing this, and more type-safe ways. Try boost filesystem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I followed the steps provided in the Zxing project. I have created a single
In my project I have provided an option for save multiple credentials. When a
I have inherited a project, that provides an order form to a customer. The
I have project asp.net with namespace test and I'm using resources (files Resource.resx and
I have a C++ project that have like 15+ external libraries installed with a
We have an existing java-based heavyweight project that needed an interactive script interpreter. After
I have a small project that I'm working with inheritance and polymorphism. I have
I have created a project in NetBeans by downloading some third party jars of
In my project that uses autoconf and automake, I have two executables, say foo
Hello all I have some very important system files which I want to protect

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.