Re: Equivalent of "du" utility in Unix or Sys module ?

"Doyle Jonathan [email protected] [ocaml_beginners]" <[email protected]>
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <[email protected]>
      De : "'Mr. Herr' [email protected] [ocaml_beginners]" <[email protected]>
 À : [email protected] 
 Envoyé le : Dimanche 21 juin 2015 18h40
 Objet : Re: "ocaml_beginners"::[] Equivalent of "du" utility in Unix or Sys module ?
   
     Indeed. This is cleaner than having to parse an output string.
 
 On 21.06.2015 13:09, [email protected] [ocaml_beginners] wrote:
  
    In the ocaml interpreter, I can type 
 
 Sys.command "du -d 1 pathformydirectory ";;
 
 to inspect the disk usage in a given directory.
 
 The problem is, the result is of type unit and I would prefer a result of type, say, (string*int) list.
 
  Is there a function from the Unix or Sys module that does this ?
 
   
 If you do it right, you will get back a string from the command execution, or a string list, but not a (string*int) list.
 
 You will have to scan the input.
 
 Another proposal: why don't you just write "du" in OCaml?
 
 Read the directory with Sys.readdir, make Unix.stat for every entry, go through the list, 
 for files collect the size, for directories you have to make Sys.readdir, make Unix.stat for every entry...
 
 Get the idea? The perfect beginners project to get some list processing and recursion done, fully functional.
 
 /Str. 
  #yiv5486039003 #yiv5486039003 -- #yiv5486039003ygrp-mkp {border:1px solid #d8d8d8;font-family:Arial;margin:10px 0;padding:0 10px;}#yiv5486039003 #yiv5486039003ygrp-mkp hr {border:1px solid #d8d8d8;}#yiv5486039003 #yiv5486039003ygrp-mkp #yiv5486039003hd {color:#628c2a;font-size:85%;font-weight:700;line-height:122%;margin:10px 0;}#yiv5486039003 #yiv5486039003ygrp-mkp #yiv5486039003ads {margin-bottom:10px;}#yiv5486039003 #yiv5486039003ygrp-mkp .yiv5486039003ad {padding:0 0;}#yiv5486039003 #yiv5486039003ygrp-mkp .yiv5486039003ad p {margin:0;}#yiv5486039003 #yiv5486039003ygrp-mkp .yiv5486039003ad a {color:#0000ff;text-decoration:none;}#yiv5486039003 #yiv5486039003ygrp-sponsor #yiv5486039003ygrp-lc {font-family:Arial;}#yiv5486039003 #yiv5486039003ygrp-sponsor #yiv5486039003ygrp-lc #yiv5486039003hd {margin:10px 0px;font-weight:700;font-size:78%;line-height:122%;}#yiv5486039003 #yiv5486039003ygrp-sponsor #yiv5486039003ygrp-lc .yiv5486039003ad {margin-bottom:10px;padding:0 0;}#yiv5486039003 #yiv5486039003actions {font-family:Verdana;font-size:11px;padding:10px 0;}#yiv5486039003 #yiv5486039003activity {background-color:#e0ecee;float:left;font-family:Verdana;font-size:10px;padding:10px;}#yiv5486039003 #yiv5486039003activity span {font-weight:700;}#yiv5486039003 #yiv5486039003activity span:first-child {text-transform:uppercase;}#yiv5486039003 #yiv5486039003activity span a {color:#5085b6;text-decoration:none;}#yiv5486039003 #yiv5486039003activity span span {color:#ff7900;}#yiv5486039003 #yiv5486039003activity span .yiv5486039003underline {text-decoration:underline;}#yiv5486039003 .yiv5486039003attach {clear:both;display:table;font-family:Arial;font-size:12px;padding:10px 0;width:400px;}#yiv5486039003 .yiv5486039003attach div a {text-decoration:none;}#yiv5486039003 .yiv5486039003attach img {border:none;padding-right:5px;}#yiv5486039003 .yiv5486039003attach label {display:block;margin-bottom:5px;}#yiv5486039003 .yiv5486039003attach label a {text-decoration:none;}#yiv5486039003 blockquote {margin:0 0 0 4px;}#yiv5486039003 .yiv5486039003bold {font-family:Arial;font-size:13px;font-weight:700;}#yiv5486039003 .yiv5486039003bold a {text-decoration:none;}#yiv5486039003 dd.yiv5486039003last p a {font-family:Verdana;font-weight:700;}#yiv5486039003 dd.yiv5486039003last p span {margin-right:10px;font-family:Verdana;font-weight:700;}#yiv5486039003 dd.yiv5486039003last p span.yiv5486039003yshortcuts {margin-right:0;}#yiv5486039003 div.yiv5486039003attach-table div div a {text-decoration:none;}#yiv5486039003 div.yiv5486039003attach-table {width:400px;}#yiv5486039003 div.yiv5486039003file-title a, #yiv5486039003 div.yiv5486039003file-title a:active, #yiv5486039003 div.yiv5486039003file-title a:hover, #yiv5486039003 div.yiv5486039003file-title a:visited {text-decoration:none;}#yiv5486039003 div.yiv5486039003photo-title a, #yiv5486039003 div.yiv5486039003photo-title a:active, #yiv5486039003 div.yiv5486039003photo-title a:hover, #yiv5486039003 div.yiv5486039003photo-title a:visited {text-decoration:none;}#yiv5486039003 div#yiv5486039003ygrp-mlmsg #yiv5486039003ygrp-msg p a span.yiv5486039003yshortcuts {font-family:Verdana;font-size:10px;font-weight:normal;}#yiv5486039003 .yiv5486039003green {color:#628c2a;}#yiv5486039003 .yiv5486039003MsoNormal {margin:0 0 0 0;}#yiv5486039003 o {font-size:0;}#yiv5486039003 #yiv5486039003photos div {float:left;width:72px;}#yiv5486039003 #yiv5486039003photos div div {border:1px solid #666666;height:62px;overflow:hidden;width:62px;}#yiv5486039003 #yiv5486039003photos div label {color:#666666;font-size:10px;overflow:hidden;text-align:center;white-space:nowrap;width:64px;}#yiv5486039003 #yiv5486039003reco-category {font-size:77%;}#yiv5486039003 #yiv5486039003reco-desc {font-size:77%;}#yiv5486039003 .yiv5486039003replbq {margin:4px;}#yiv5486039003 #yiv5486039003ygrp-actbar div a:first-child {margin-right:2px;padding-right:5px;}#yiv5486039003 #yiv5486039003ygrp-mlmsg {font-size:13px;font-family:Arial, helvetica, clean, sans-serif;}#yiv5486039003 #yiv5486039003ygrp-mlmsg table {font-size:inherit;font:100%;}#yiv5486039003 #yiv5486039003ygrp-mlmsg select, #yiv5486039003 input, #yiv5486039003 textarea {font:99% Arial, Helvetica, clean, sans-serif;}#yiv5486039003 #yiv5486039003ygrp-mlmsg pre, #yiv5486039003 code {font:115% monospace;}#yiv5486039003 #yiv5486039003ygrp-mlmsg * {line-height:1.22em;}#yiv5486039003 #yiv5486039003ygrp-mlmsg #yiv5486039003logo {padding-bottom:10px;}#yiv5486039003 #yiv5486039003ygrp-msg p a {font-family:Verdana;}#yiv5486039003 #yiv5486039003ygrp-msg p#yiv5486039003attach-count span {color:#1E66AE;font-weight:700;}#yiv5486039003 #yiv5486039003ygrp-reco #yiv5486039003reco-head {color:#ff7900;font-weight:700;}#yiv5486039003 #yiv5486039003ygrp-reco {margin-bottom:20px;padding:0px;}#yiv5486039003 #yiv5486039003ygrp-sponsor #yiv5486039003ov li a {font-size:130%;text-decoration:none;}#yiv5486039003 #yiv5486039003ygrp-sponsor #yiv5486039003ov li {font-size:77%;list-style-type:square;padding:6px 0;}#yiv5486039003 #yiv5486039003ygrp-sponsor #yiv5486039003ov ul {margin:0;padding:0 0 0 8px;}#yiv5486039003 #yiv5486039003ygrp-text {font-family:Georgia;}#yiv5486039003 #yiv5486039003ygrp-text p {margin:0 0 1em 0;}#yiv5486039003 #yiv5486039003ygrp-text tt {font-size:120%;}#yiv5486039003 #yiv5486039003ygrp-vital ul li:last-child {border-right:none !important;}#yiv5486039003
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.