CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: DeleteDirectory

  1. #1
    Join Date
    Nov 2006
    Posts
    292

    DeleteDirectory

    Hi all, Im trying to figure out how to use the DeleteDirectory API. I went to MSDN and it looks pretty straight forward. But i got a undeclared identifier error.

    my code

    Code:
    #include <windows.h>
    
    int main(){
    	DeleteDirectory("C:\\test", NULL, NULL, NULL);
    	return 0;
    }
    I was just trying to be simple so i could figure out how to use it. Any suggestions are greatly appreciated.

    The error:

    [quote]
    error C2065: 'DeleteDirectory' : undeclared identifier
    [/code]

    Thanx in advance!

  2. #2
    Join Date
    Jun 2006
    Location
    M31
    Posts
    885

    Re: DeleteDirectory

    Quote Originally Posted by dellthinker
    error C2065: 'DeleteDirectory' : undeclared identifier
    That's because there's no such API. I take it you're referring to RemoveDirectory...

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: DeleteDirectory

    The MSDN I have doesn't list a DeleteDirectory API.

  4. #4
    Join Date
    Nov 2006
    Posts
    292

    Re: DeleteDirectory

    Thanx for your replies. DeleteDirectory() seems to be a working API. But according to MSDN.

    RemoveDirectory Function

    Deletes an existing empty directory.

    To perform this operation as a transacted operation, use the RemoveDirectoryTransacted function.
    So what if the dir has files inside of it? How would i manage to delete one with files in it?

  5. #5
    Join Date
    Jun 2006
    Location
    M31
    Posts
    885

    Re: DeleteDirectory

    Quote Originally Posted by dellthinker
    DeleteDirectory() seems to be a working API.
    Say what?

    Quote Originally Posted by dellthinker
    So what if the dir has files inside of it? How would i manage to delete one with files in it?
    FindFirstFile, FindNextFile, DeleteFile.

  6. #6
    Join Date
    Jul 2007
    Location
    Richmond, BC
    Posts
    79

    Re: DeleteDirectory

    So what if the dir has files inside of it? How would i manage to delete one with files in it?
    I used SHFileOperation to delete all the files.
    Code:
            SHFILEOPSTRUCT fileOpStruct;
            fileOpStruct.hwnd = this->m_hWnd; 
            fileOpStruct.wFunc = FO_DELETE;
            fileOpStruct.pFrom = L"path_to_your_folder\*.*"
            fileOpStruct.pTo = 0;
            fileOpStruct.fFlags = FOF_SIMPLEPROGRESS;
            fileOpStruct.lpszProgressTitle =L"Deleting old files";
            int res = SHFileOperation(&fileOpStruct);
            if (res || fileOpStruct.fAnyOperationsAborted)
            {
                 // error or user doesn't confirm deleting 
            }
            else
            {
                // files were deleted, now directory can be deleted.
            }

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: DeleteDirectory

    Quote Originally Posted by dellthinker
    Thanx for your replies. DeleteDirectory() seems to be a working API. But according to MSDN.



    So what if the dir has files inside of it? How would i manage to delete one with files in it?
    You said DeleteDirectory, but posted MSDN saying RemoveDirectory.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured