SHFileOpertion and FO_DELETE

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon Jefferies

    SHFileOpertion and FO_DELETE

    Hello,

    I am trying to delete a file using SHFileOperation , but get the error code
    1026.

    Code snippet:

    SHFILEOPSTRUCT fo;
    ZeroMemory(&fo, sizeof(fo));
    fo.fFlags = FOF_ALLOWUNDO | FOF_FILESONLY;
    fo.wFunc = FO_DELETE; // delete contents of this folder
    fo.pFrom = szFilename;
    int nSuccessCode = SHFileOperation (&fo);

    The file does exist and have tried with other files/paths etc but these do
    not work.

    Any ideas?
    TIA
    Simon Jefferies


  • KC

    #2
    Re: SHFileOpertion and FO_DELETE

    There are a few reason why the operation failed. The file could be in use
    and thus the deletion failed.

    Another reason is, szFilename is not double NULL terminated. To ensure a
    string is double NULL terminated you can initialize your buffer to NULL.

    char szFileName[260];
    memset(szFileNa me, 0, sizeof(szFileNa me));

    strcpy(szFileNa me, "C:\\Hello" );

    Both member of SHFILEOPSTRUCT (pFrom and pTo) must be double NULL
    terminated if they contain value.

    Regards,
    KC

    "Simon Jefferies" <jefferies_simo n@hotmail.com> wrote in message
    news:OmlbLiZtDH A.1872@TK2MSFTN GP09.phx.gbl...[color=blue]
    > Hello,
    >
    > I am trying to delete a file using SHFileOperation , but get the error code
    > 1026.
    >
    > Code snippet:
    >
    > SHFILEOPSTRUCT fo;
    > ZeroMemory(&fo, sizeof(fo));
    > fo.fFlags = FOF_ALLOWUNDO | FOF_FILESONLY;
    > fo.wFunc = FO_DELETE; // delete contents of this folder
    > fo.pFrom = szFilename;
    > int nSuccessCode = SHFileOperation (&fo);
    >
    > The file does exist and have tried with other files/paths etc but these do
    > not work.
    >
    > Any ideas?
    > TIA
    > Simon Jefferies
    >
    >[/color]


    Comment

    • Deepak

      #3
      Re: SHFileOpertion and FO_DELETE

      Hi Simon Jefferies
      try this code it seems to work i tried this

      SHFILEOPSTRUCT s ;
      ::ZeroMemory ( &s, sizeof ( s ) ) ; // Initialize the structure

      CString f = "C:\\MyFold er" ;
      //CString t = "D:\\" ;

      char from [ MAX_PATH ], to [ MAX_PATH ] ; // buffer used to copy source and
      target path

      strcpy ( from, f ) ;
      int l = f.GetLength( ) ;
      from[l+1] = '\0' ;

      //strcpy ( to, t ) ;
      //l = t.GetLength( ) ;
      //to[l+1] = '\0' ;

      // Set the values in structure
      s.hwnd = this -> m_hWnd ;
      s.wFunc = FO_DELETE ;
      s.pFrom = ( LPCTSTR ) from ;
      //s.pTo = ( LPCTSTR ) to ;
      s.fFlags = FOF_SIMPLEPROGR ESS ;
      s.lpszProgressT itle = "Moving files..." ;

      ::SHFileOperati on ( &s ) ;

      ----
      Deepak



      "Simon Jefferies" <jefferies_simo n@hotmail.com> wrote in message
      news:OmlbLiZtDH A.1872@TK2MSFTN GP09.phx.gbl...[color=blue]
      > Hello,
      >
      > I am trying to delete a file using SHFileOperation , but get the error code
      > 1026.
      >
      > Code snippet:
      >
      > SHFILEOPSTRUCT fo;
      > ZeroMemory(&fo, sizeof(fo));
      > fo.fFlags = FOF_ALLOWUNDO | FOF_FILESONLY;
      > fo.wFunc = FO_DELETE; // delete contents of this folder
      > fo.pFrom = szFilename;
      > int nSuccessCode = SHFileOperation (&fo);
      >
      > The file does exist and have tried with other files/paths etc but these do
      > not work.
      >
      > Any ideas?
      > TIA
      > Simon Jefferies
      >
      >[/color]


      Comment

      Working...