f



Deleting a directory with all its files?

Hello,

What is the best method to recursively delete a
directories with all its contents i.e. files and
subdirectories?

regards,
Karam


	
		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail 

---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wx-users-help@lists.wxwidgets.org

0
karam_chand03
8/9/2004 3:01:02 PM
comp.soft-sys.wxwindows 21076 articles. 0 followers. Post Follow

4 Replies
266 Views

Similar Articles

[PageSpeed] 20

On Mon, 9 Aug 2004 07:58:51 -0700 (PDT), you wrote:

>Hello,
>
>What is the best method to recursively delete a
>directories with all its contents i.e. files and
>subdirectories?


I used wxDir and its traverser.  The problem is, it doesn't work out
of the box for deleting directories and sub directories.

I had to rewrite part of the traversing code to do a depth first
search. =20

I have been meaning to submit this to the project..  Hopefully I will
get to it soon..

Maybe someone has an easier way?

Randall Fox

---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wx-users-help@lists.wxwidgets.org

0
fox_no_spam
8/9/2004 6:36:25 PM
Hello,

Can I have the code?

Regards,
Karam

--- Randall Fox <fox_no_spam-usenet001@yahoo.com>
wrote:

> On Mon, 9 Aug 2004 07:58:51 -0700 (PDT), you wrote:
> 
> >Hello,
> >
> >What is the best method to recursively delete a
> >directories with all its contents i.e. files and
> >subdirectories?
> 
> 
> I used wxDir and its traverser.  The problem is, it
> doesn't work out
> of the box for deleting directories and sub
> directories.
> 
> I had to rewrite part of the traversing code to do a
> depth first
> search.  
> 
> I have been meaning to submit this to the project.. 
> Hopefully I will
> get to it soon..
> 
> Maybe someone has an easier way?
> 
> Randall Fox
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> wx-users-unsubscribe@lists.wxwidgets.org
> For additional commands, e-mail:
> wx-users-help@lists.wxwidgets.org
> 
> 



		
__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail

---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wx-users-help@lists.wxwidgets.org

0
karam_chand03
8/10/2004 1:50:19 AM
Karam Chand <karam_chand03@yahoo.com>:
> Hello,
>
> Can I have the code?

Sample code for traversing wxDir is in manual.
http://www.wxwidgets.org/manuals/2.5.2/wx_wxdir.html

ABX

---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wx-users-help@lists.wxwidgets.org

0
abx
8/10/2004 6:09:09 AM
On Mon, 9 Aug 2004 18:46:57 -0700 (PDT), you wrote:

>Hello,
>
>Can I have the code?

Sure, but my code was imbedded in my app, so you may have to change it
a bit to make it go..   I don't offer any support on this version...
Use at your own risk..

Randall Fox
---------------------

size_t Dlg_Build::MyWorkerThread::MyDir::Traverse(wxDirTraverser&
sink,
                       const wxString& filespec,
                       int flags) const
{
    wxCHECK_MSG( IsOpened(), (size_t)-1,
                 _T("dir must be opened before traversing it") );
    // the total number of files found
    size_t nFiles =3D 0;
    // the name of this dir with path delimiter at the end
    wxString prefix =3D GetName();
    prefix +=3D wxFILE_SEP_PATH;
    // first, recurse into subdirs
    if ( flags & wxDIR_DIRS )
    {
        wxString dirname;
        bool cont =3D GetFirst(&dirname, _T(""), wxDIR_DIRS |
wxDIR_HIDDEN);
        while ( cont )
        {
            wxDirTraverseResult res;
            // if this is a depth first search, we don't want to
report finding it
            // until AFTER we have visited all the children -- this is
useful
            // if we are DELETING the directory, because we need to
delete its children
            // first
            if (!(flags & wxDEPTH_FIRST)) // if not a depth search
search
            {
                // calls the handler before entering the directory
                // this is a "visit"
                // this is NOT a depth search traversal
                res =3D sink.OnDir(prefix + dirname); //call the handler
            }
            else res =3D wxDIR_CONTINUE; // if it is depth first, keep
going
            if ( res =3D=3D wxDIR_STOP ) break;
            if ( res =3D=3D wxDIR_CONTINUE )
            {
                // now enter or visit the directory we found
                MyDir subdir(prefix + dirname);
                if ( subdir.IsOpened() )
                {
                    nFiles +=3D subdir.Traverse(sink, filespec, flags);
                }
            }
            if (flags & wxDEPTH_FIRST) // if a depth search
            {
                // now visit the directory after its children have
been visited
                res =3D sink.OnDir(prefix + dirname); // calls the
handler
                // return value really doesn't matter, since in a
depth first=20
                // search we have already visited all the children, so
there is=20
                // really nothing that can be done with the return
value except
                // if it is a stop command, maybe you want to stop
after processing
                // a specific directory?
                if ( res =3D=3D wxDIR_STOP ) break;
                wxASSERT_MSG((res =3D=3D wxDIR_IGNORE) || (res =3D=3D
wxDIR_CONTINUE),
                            _T("unexpected OnDir() return value") );
            }
            else
            {
                wxASSERT_MSG((res =3D=3D wxDIR_IGNORE) || (res =3D=3D
wxDIR_CONTINUE),
                            _T("unexpected OnDir() return value") );
            }
            cont =3D GetNext(&dirname);
        }
    }
    // now enum our own files
    if ( flags & wxDIR_FILES )
    {
        flags &=3D ~wxDIR_DIRS;
        wxString filename;
        bool cont =3D GetFirst(&filename, filespec, flags);
        while ( cont )
        {
            wxDirTraverseResult res =3D sink.OnFile(prefix + filename);
            if ( res =3D=3D wxDIR_STOP )
                break;
            wxASSERT_MSG( res =3D=3D wxDIR_CONTINUE,
                          _T("unexpected OnFile() return value") );
            nFiles++;
            cont =3D GetNext(&filename);
        }
    }
    return nFiles;
}




---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wx-users-help@lists.wxwidgets.org

0
fox_no_spam
8/11/2004 3:13:59 PM
Reply: