Query on DzDir

Richard HaseltineRichard Haseltine Posts: 100,867

I was just trying to write a routine to ensure a path existed, and thought to use DzDir to check for existence and walk up the tree if not (using a recursive function) until hit a real folder at which I could walk back down again creating the needed folders. DzDir.cdUp() works if DzDir is itself pointing to a non-existent directory, but not if the parent directory is also non-existent. I've got round the problem by manually truncating the path as a string, but is that the way cdUp() should be behaving? If not I'll bug report it.

Comments

  • rbtwhizrbtwhiz Posts: 2,250
    edited September 2013

    Ensuring that a path exists is actually much easier than that... see below.

    var sPath = "C:/TEST/DzDir/mkpath";
    var oDir = new DzDir( sPath );
    if( !oDir.mkpath( sPath ) ){
     var sMessage = String("Could not create path:\n%1").arg( sPath );
     MessageBox.warning(sMessage, "Warning", "OK", "");
    }

    DzDir is basically just a wrapper for [an earlier version of]* QDir. So QDir::cdUp() describes the expected behavior.

    *Its been a while since the wrapper was updated to provide script access to some of the newer functions you'll notice in the Qt docs.

    -Rob

    Post edited by rbtwhiz on
  • Richard HaseltineRichard Haseltine Posts: 100,867
    edited December 1969

    Ah, thank you - that probably means I don't even need a separate function. My excuse is that I am not yet used to these glasses.

Sign In or Register to comment.