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

  • Home
  • SEARCH
  • 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 7493569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:02:52+00:00 2026-05-29T17:02:52+00:00

Im trying to copy a directory to a new location. So I am using

  • 0

Im trying to copy a directory to a new location. So I am using SHFileOperation/SHFILEOPSTRUCT as follows:

SHFILEOPSTRUCT sf;
memset(&sf,0,sizeof(sf));
sf.hwnd = 0;
sf.wFunc = FO_COPY;
dirName += "\\*.*";
sf.pFrom = dirName.c_str();
string copyDir = homeDir + "\\CopyDir";
sf.pTo = copyDir.c_str();
sf.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI;

int n = SHFileOperation(&sf);
if(n != 0)
{
    int x = 0;
}

So I set the values as above. There is a file I created in the folder (I have closed the Handle so it should be fine to move). The SHFileOperation call is returning 2, but I cant find anywhere where these error codes are explained. Does anyone know where I can find out what 2 means, or does anyone have any ideas why it might not be working? Cheers

  • 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-29T17:02:54+00:00Added an answer on May 29, 2026 at 5:02 pm

    Error code 2 means The system cannot find the file specified.

    See Windows System Error Codes for full listing of error descriptions, or write a function that will obtain the description for the error code:

    std::string error_to_string(const DWORD a_error_code)
    {
        // Get the last windows error message.
        char msg_buf[1025] = { 0 };
    
        // Get the error message for our os code.
        if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 
                          0,
                          a_error_code,
                          0,
                          msg_buf,
                          sizeof(msg_buf) - 1,
                          0))
        {
            // Remove trailing newline character.
            char* nl_ptr = 0;
            if (0 != (nl_ptr = strchr(msg_buf, '\n')))
            {
                *nl_ptr = '\0';
            }
            if (0 != (nl_ptr = strchr(msg_buf, '\r')))
            {
                *nl_ptr = '\0';
            }
    
            return std::string(msg_buf);
        }
    
        return std::string("Failed to get error message");
    }
    

    From reading the documentation for SHFileOperation the strings specified for pTo and pFrom must be double null terminated: yours are only singly null terminated. Try the following:

    dirName.append(1, '\0');
    sf.pFrom = dirName.c_str();
    string copyDir = homeDir + "\\CopyDir";
    copyDir.append(1, '\0');
    sf.pTo = copyDir.c_str();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to copy a file to a new location, maintaining directory structure. $source
I'm trying to copy a directory using the Ant copy task. I am a
I am new to programming, trying to copy files from one location to another,
I am relatively new to python. I am trying to copy a directory to
I am trying to copy the contents of certain folders to another folder using
I am trying to copy data from my MYSQL table to SQL Server using
I have a list of files that I'm trying to copy and move (using
I'm trying to copy a file to another directory with Commons ' fileUtils. I
Trying to write a simple C# script to copy file to directory one level
I'm trying to copy a single file using copy-item to a remote computer using

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.