?
Solved

SHFileOperation()

Posted on 2000-01-29
3
Medium Priority
?
214 Views
Last Modified: 2010-04-10
I want to use SHFileOperation() to copy/move files.
  For some files, SHFileOperation() will succeed. But for other Files, SHFileOperation() will return a ERROR MessageBox which said "File System Error(1026)". Why?
 
  ===CODE BEGIN===
        UINT OpResult;
      char SrcDir[MAX_PATH];
      char DstDir[MAX_PATH];
      SHFILEOPSTRUCT sendFileOp;

        memset(&sendFileOp,0,sizeof(sendFileOp));
      m_EDITCtrl.GetWindowText(DstDir,MAX_PATH);
      int n;

      for(n=0;n<sumFiles;n++){
           sendFileOp.hwnd=GetSafeHwnd();
           if(m_radioMode==0){
                 sendFileOp.wFunc=FO_COPY;
             }
           else{
                  sendFileOp.wFunc=FO_MOVE;
             }
       m_LISTsCtrl.GetText(n,SrcDir);
         //the list box contains the files which to be copied/moved.

       sendFileOp.pFrom=SrcDir;
         sendFileOp.pTo=DstDir;
         sendFileOp.fFlags=NULL;
         sendFileOp.hNameMappings=NULL;
         sendFileOp.lpszProgressTitle="FreeSender is sending";

           OpResult=SHFileOperation(&sendFileOp);
      }
 ===CODE END===

Looking forwards your suggestion?
0
Comment
Question by:henry3
  • 2
3 Comments
 
LVL 6

Expert Comment

by:DrDelphi
ID: 2410121
Have you tried call GetLastError to see what error 1026 is?
0
 
LVL 22

Expert Comment

by:nietod
ID: 2412041
Are you sure that is the error code, It does not seem to be defined.

Is it possible that some of the files are open?  If a file is open it can't be moved.
0
 
LVL 22

Accepted Solution

by:
nietod earned 90 total points
ID: 2412082
One potential problem is

m_LISTsCtrl.GetText(n,SrcDir);
                        //the list box contains the files which to be copied/moved.

The source string must be DOUBLE NUL terminated.   But GetText() returns a string that is only single NUL terminated.  To get around this, fill SrcDir with NULs before doing the GetText.  I suspect that the problem will go away (certainly one problem will go away.)
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

593 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question