How to delete a directory

DraagonStormDraagonStorm Posts: 748

I've tried a lot of different ways... Some has shown no error, but still the directory is not being deleted... Help!

What I want to do is first verify the directory exists, and if it does, delete it.

Comments

  • Richard HaseltineRichard Haseltine Posts: 100,939
    edited December 1969

    You've tried DzDir.rmDir() ?

  • DraagonStormDraagonStorm Posts: 748
    edited December 1969

    You've tried DzDir.rmDir() ?

    Yes... Maybe I'm doing it wrong.. Can you post some sample code that you know works?

  • Richard HaseltineRichard Haseltine Posts: 100,939
    edited December 1969

    This works - comment out the rmdir line on first run so you can see the folders created, then try it again and it will remove the expendable folder.

    testDir = new DzDir( "c:/test/expendable" );
    // If successful...
    if ( testDir ) {
     // .... try to create the path, if it doesn't already exist
     if ( testDir.mkpath( "c:/test/expendable" ) ) {
      testDir.rmdir();
     }
    }
  • DraagonStormDraagonStorm Posts: 748
    edited December 1969

    Richard, Does the folder have to be empty to remove it?

  • Richard HaseltineRichard Haseltine Posts: 100,939
    edited December 1969

    I would expect so, yes. It's like the DOS command, which as I recall worked only on empty folders (unlike killtree, or whatever it was, or the Windows delete key in Explorer)

Sign In or Register to comment.