#1
  1. Some day I will be a Lambda!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    NJ
    Posts
    18
    Rep Power
    0

    Parse a physical drive


    I need to parse a physical drive and get a result similar to a [DIV /S] from the command line. I need to know how many nodes from the root each file is and the file type. Example: FileName:="TeastMe.txt" NodeCount:="14" or something. Could anyone help me please.

    Thank You
    Eric Cashwell
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Location
    Belgrade, Yugoslavia
    Posts
    7
    Rep Power
    0

    not quite clear


    It's not quite clear what are you trying to accomplish.

    If what you want is to parse a string like "/home/user/public_html/welcome.html" (or similarly, "C:\home\user\public_html\welcome.html") and return something like
    Code:
       name=welcome.html
       level=3 // with zero-based level number
    then it's a trivial task of simply searching the string for the occurence of '/' or '\'.

    If you're looking for a concrete implementation in a particular language, then you should probably ask it in that language's forum (I would call it bad taste to resort here to any language in particular :)


    If you actually want to really "parse a physical drive" and get the same result for a given file name, it would require knowledge of the underlying filesystem. Since there is a plethora of those available (among them Ext2, Ext3, NTFS, FAT[32], ReiserFS, UFS; just to mention a few), so it's impossible to answer your question. Even then, it's not a matter of algorithms, but rather a question of "specification of filesystem implementation".


    If your question is something completely different, then accept my apology for not knowing any better.

    That's it.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    191
    you asked in the algorithms forum, this one is easy. here you go:
    (pseudo-code)
    Code:
    global file_list;
    function add_to_list(n,d,t) {
      l=length(file_list);
      file_list[l]->name=n;
      file_list[l]->level=d;
      file_list[l]->type=t;
    }
    
    function parse_dir(dirname) {
      depth++;
      static depth;
      for each entry {
          add_to_list(dirname+"\"+entry.name,depth,entry.type);
        if (is it a directory) {
          parse_dir(dirname+"\"+entry.name); // recursive call to get all files inside
        }
      }
    }
    
    parse_dir("(DRIVE LETTER):\")
    does this fit to your question?

IMN logo majestic logo threadwatch logo seochat tools logo