Check if Directory is empty



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/10/2008 at 15:32, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R11 
    Platform:   Windows  ;   Mac OSX  ; 
    Language(s) :   C.O.F.F.E.E  ;

    ---------
    Getting the grips of adding, reading, deleting etc. files pretty well.
    As of R11, I'd like to add my licenses in the UserPrefs as suggested, in a folder.
    But, if there are now license files in this folder, I'd like to
    delete it as well.

    So what I can't figure out is how to check for an empty directory
    (Folder with no files in it on the disc).
    I can brows to this folder but then since I have no name to add
    to the path I'm stuck.

    Any pointers of how to do that?

    Cheers
    Lennart



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/10/2008 at 16:03, xxxxxxxx wrote:

    Use the BrowseFiles class.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/10/2008 at 16:45, xxxxxxxx wrote:

    Hi Robert. Yup that is what I'm trying.....
    But I can't get a TRU or FALSE out of it as it seems..

    > \>         var bf = new(BrowseFiles); \>       var path = GeGetStartupWritePath(); \>       path->AddLast("MyFolder"); \>       bf->Init(path,FALSE); \>       var name = bf->GetName(); \>       if(name) \>       println("Name is ",name); \>

    Thing is this only prints the "Name is" part, the rest (var name)
    simply doesn't print anything, its blank(!?).

    So, I'm still a bit lost I'm afraid..
    There is the GetNext() option, but not "GetDown()" or GetIn() to
    "get into" the folder to check.

    Cheers
    Lennart



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/10/2008 at 16:55, xxxxxxxx wrote:

    There is an example at the bottom of the BrowseFiles documentation:

    var bf   = new(BrowseFiles);
    var path = GeStartupPath();

    bf->Init(path,FALSE);

    while (bf->GetNext())
    {
        if (bf->IsDir())
          println("dir ",bf->GetName());
        else
          println("file ",bf->GetName());
    }

    bf->GetNext() gets the first then next files/folders under the folder set in bf->Init().



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/10/2008 at 17:15, xxxxxxxx wrote:

    Ah, I used that example to start with and also got that "blank" print.
    Just tried this:

    > \> var bf   = new(BrowseFiles); \> var path = GeGetStartupWritePath(); \> path->AddLast("MyFolder"); \> bf->Init(path,FALSE); \> \> if(bf->GetNext() != FALSE) \> println("Something here!"); \> else \> println("Nope, emty"); \>

    And even if MyFolder was empty, it wasn't!
    There is a frigging hidden ".DS_Store" file there!

    So the BrowseFiles seems to work but what to do with hidden files?
    I'm on Mac, is there anything similar happening in Windows?

    Cheers
    Lennart



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/10/2008 at 17:54, xxxxxxxx wrote:

    On that in COFFEE, I don't know. You may need to check for that particular file by name when you get a hit, ignore it and continue on.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/10/2008 at 18:09, xxxxxxxx wrote:

    Thanks Robert.
    It looks as if I'm on the wrong track anyway....
    Recreating the "MyFolder" (From Finder) so there is nothing in it,
    even no .DS_Store file, I still get a "Something here!" using the code
    above.

    Maybe someone from Maxon have a tip after the weekend.

    Cheers and thanks
    Lennart



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 20/10/2008 at 05:44, xxxxxxxx wrote:

    I can not confirm this. If I create an empty folder on OSX with Finder->New Folder it is empty for Cinema as well. My code:

    > \> var path = new(Filename); \> if(!path->PathSelect("Select Path")) return; \> \> var bf = new(BrowseFiles); \> bf->Init(path,FALSE); \> \> if(bf->GetNext()) println("not empty"); \> else println("empty"); \>

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 20/10/2008 at 05:47, xxxxxxxx wrote:

    Thanks Matthias. I got it working (and have learnt a lot about file handling the last couple of days because of making license files:) )
    Sorry to not tell.

    Cheers
    Lennart


Log in to reply