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 3720590
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:16:02+00:00 2026-05-19T05:16:02+00:00

i am just trying to use copyfile to copy a file, it is as

  • 0

i am just trying to use copyfile to copy a file, it is as simple as that but it wont work. i have googled it and looked at 20 links and they all say “object.CopyFile ( source, destination[, overwrite] ) ”

The problem is i can’t get it to copy the txt file for me, i have tryed running it as an admin but still does not work. also i need to put the source and destination as
lpctstr (because it wont compile with out using Multi-Byte Character and my other code will not work unless i Use Unicode Character Set).

My code is

#include <iostream>
#include <Windows.h>

using namespace std;

int main()
{

 CopyFile("C:\\Somefolder\\file.txt","C:\\folder\\file.txt",0);
 return 0;
}

i am running windows 7, vc++ 2010, compiling as debug, sorry if i missed anything.

  • 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-05-19T05:16:04+00:00Added an answer on May 19, 2026 at 5:16 am

    Replace the line:

    CopyFile("C:\\Somefolder\\file.txt","C:\\folder\\file.txt",0);
    

    with:

    BOOL b = CopyFile("C:\\Somefolder\\file.txt","C:\\folder\\file.txt",0);
    if (!b) {
        cout << "Error: " << GetLastError() << endl;
    } else {
        cout << "Okay " << endl;
    }
    

    That should tell you if and why it’s failing. The error code, once you have it, can be looked up here.


    And if, as your comment indicates, you’re getting ERROR_PATH_NOT_FOUND, the first thing I’d be looking at is whether the paths c:\somefolder and c:\folder exist as well as the actual source file c:\somefolder\file.txt.

    One special thing to keep in mind: CopyFile won’t create the directory for the target file, it has to exist before you try to copy. There are numerous ways you can do this, such as with CreateDirectory, CreateDirectoryEx or SHCreateDirectoryEx).

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

Sidebar

Related Questions

I have some test code that i'm just trying to use to figure out
I was just trying to use Robotium in an Android JUnit Test, but the
I'm trying to use the following code (poorly written, but it's just a proof
I'm trying to use an external library (wingraph) in a simple program. I have
I just trying to use a update in my application, but i just can't.
I am just trying to use this as a very simple register system and
I'm trying to use LinqToEntities and just noticed that there are no foreign key
I'm trying to use a select with an onChange event and I just need
I'm trying to use sed to clean up lines of URLs to extract just
I just made my first .net website. I'm trying to use the following line

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.