CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 1999
    Location
    Manchester, UK
    Posts
    1

    Deleting Directories

    I am trying to delete a directory using the commands DeleteFile & RemoveDirectory, but I get 'Access is denied.' or 'The process cannot access the file because it is being used by another process.'

    I am using WinNT4(sp4) VC6 (sp2). The program I am writing is MFC based.

    Thakn you for your time.


    Peter Tewkesbury
    Software Engineer
    NedGraphics Print LTD

  2. #2
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: Deleting Directories


    you can not delete c:\f1 in one go if c:\f1 has sub folders
    you have to delete each sub folder first and then c:\f1, recursively

    Sally


  3. #3
    Join Date
    May 1999
    Posts
    66

    Re: Deleting Directories

    I am having a similar problem to yours with an mfc based program. Have you found a fix? If so, could you please help me out? Thanks...


  4. #4
    Join Date
    May 1999
    Posts
    66

    Re: Deleting Directories

    I forgot to tell you earlier...There is a nice delete directory function here on codegure that someone wrote...You can search for it under NukeDirectory. The code works, I am using it. It will delete all files and subfolders within a given directory, then the directory. It takes &strDir as a parameter.


  5. #5
    Join Date
    May 1999
    Location
    Houston - TX - US
    Posts
    29

    Re: Deleting Directories

    Hi ,
    Here is the code which deletes the dir recersively .


    BOOL DeleteDirectory( CString DirectoryPath )
    {
    CFileFind finder;
    DirectoryPath += "\\*.*";

    if ( (DirectoryPath == "" || ( DirectoryPath == "c:\" ))
    return TRUE ; // make sure don't delete ROOT dir !


    BOOL bWorking = finder.FindFile(DirectoryPath);

    while (bWorking)
    {
    bWorking = finder.FindNextFile();
    if (!finder.IsDots()) //skip the dots which denote the current directory
    {
    DeleteFile((LPCTSTR)finder.GetFilePath());
    if (finder.IsDirectory())
    {
    DeleteDirectory(finder.GetFilePath());
    }
    }
    }
    finder.Close();

    if (!RemoveDirectory(LPCTSTR( DirectoryPath.Left(DirectoryPath.GetLength()-strlen("\\*.*")) + '\0')))
    {
    return FALSE;
    }
    return TRUE;
    }





    hope this helps !

    Good Luck.
    Yash.


  6. #6
    Join Date
    May 1999
    Location
    Mass, USA.
    Posts
    103

    Re: Deleting Directories

    It's important to ensure that the directory you're attempting to delete is not your default directory. So, just before you blow it away, _chdir to another directory.

    /ravi



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