1. conclusion about help!
- Posted by CAMPOS ARRIBAS- LUIS RAUL <95203695 at XAEE.UB.ES> Apr 24, 1998
- 499 views
Hi Euphorians! sorry guys,i tested the % with all the options except '%d'. the truth is that i don't want to compute the national debt... i would need more 0's!!!(eventhough we passed the Maastrich exam with a fairly note:) The aim of the program is to find the full size of a directory but it doesn't works yet cause it doesn't find the size of the subdirectories within...can someone do this?;) check out the following code! ---------------------------------------------------------------------- include file.e sequence number, path atom size -- this function will convert 'size' to a string function sprint(object x) squence s if atom(x) then return sprintf("%d", x) ----> would be better with printf()? else s =3D "{" for i =3D 1 to length(x) do s =3D s&sprint(x[i]) if i < length(x) then s =3D s & ',' end if end for s =3D s & "}" return s end if end function -- this function insert the periods in the number function convert_size( sequence size_string ) integerl, x, t, temp_t l =3D length( size_string ) x =3D 1 t =3D 3 temp_t =3D 0 temp_number =3D {} while x > 1 do temp_number =3D size_string[1] & temp_number temp_t =3D temp_t + 1 l =3D l - 1 if l =3D 0 then x =3D 1 end if if temp_t =3D t or temp_t =3D 2*t or temp_t =3D 3*t or temp_t =3D = 4*t or temp_t =3D 5*t or temp_t =3D 6*t or temp_t =3D 7*= t or temp_t =3D 8*t or temp_t =3D 9*t or temp_t =3D 10= *t and l > 0 then temp_number =3D "." & temp_number end if end while size_digit =3D temp_number return size_digit end function --- start size =3D 0 path =3D "C:\WINDOWS" -----------------> path to be tested for n =3D 1 to length( path ) do ----- it computes the globakl size of size =3D size + path[n][D_SIZE]----- the directorie without the ----- subdirectories. end for number =3D convert_size( sprint( size ) ) puts(1, number&" Bytes" ) ---------------------------------------------------------------------- Regards, Luis Ra=FAl Campos (it's my full name but i prefer just to be called Luis! :)
2. Re: conclusion about help!
- Posted by MAP <ddhinc at ALA.NET> Apr 24, 1998
- 519 views
CAMPOS ARRIBAS- LUIS RAUL wrote: > > Hi Euphorians! > sorry guys,i tested the % with all the options except '%d'. > the truth is that i don't want to compute the national debt... > i would need more 0's!!!(eventhough we passed the Maastrich > exam with a fairly note:) > The aim of the program is to find the full size of a directory but it > doesn't works yet cause it doesn't find the size of the > subdirectories within...can someone do this?;) Hello Luis, Euphoria's bin directory has a program called guru.ex, in there is a procedure that demonstrates recursing into sub directories. With some modification it should do what you're looking for. procedure walk_dir(sequence path_name) -- walk through a directory and its subdirectories -- "looking" at each file object d d = dir(path_name) while find(path_name[length(path_name)], " \\") do path_name = path_name[1..length(path_name)-1] end while if atom(d) then return end if d = sort(d) for i = 1 to length(d) do if find('d', d[i][D_ATTRIBUTES]) then if not find(d[i][D_NAME], {".", ".."}) then walk_dir(path_name & '\\' & d[i][D_NAME]) end if else look_at(path_name, d[i]) end if end for end procedure Hope this helps, Christopher D. Hickman
3. Re: conclusion about help!
- Posted by Irv Mullins <irv at ELLIJAY.COM> Apr 24, 1998
- 513 views
At 07:46 PM 4/24/98 +0000, Luis wrote: re: converting size to formatted string: Luis: there is a shorter way to do what you want: this will convert either an atom or a sequence of numbers to string form: atom n object m n = 1234567890 m = {123,552,1094949} function s_print(object n) -- converts atom to formatted string object s s = sprintf("%d",n) for i = length(s)-3 to 1 by -3 do -- insert separators s = s[1..i] & ',' & s[i+1..length(s)] end for return s end function function sprint(object n) -- convert atom or sequence object result result = {} if atom(n) then result = s_print(n) -- atom else for i = 1 to length(n) do -- sequence result = append(result, s_print(n[i])) end for end if return result end function -- test code: puts(1,sprint(n)) puts(1,"\n") m = sprint(m) for i = 1 to length(m) do puts(1,m[i] & "\n") end for Irv Spam Haiku:------------------- Silent, former pig One communal awareness Myriad pink bricks -------------------------------------
4. Re: conclusion about help!
- Posted by Robert B Pilkington <bpilkington at JUNO.COM> Apr 25, 1998
- 517 views
>re: converting size to formatted string: > >Luis: there is a shorter way to do what you want: >this will convert either an atom or a sequence of numbers >to string form: >function s_print(object n) -- converts atom to formatted string >object s > s = sprintf("%d",n) > for i = length(s)-3 to 1 by -3 do -- insert separators > s = s[1..i] & ',' & s[i+1..length(s)] > end for > return s >end function This will only work correctly with integers and positive numbers. The "%d" chops off any decimal places, and negative numbers will look like this: -3290 -3,290 -- This looks OK -321 -,321 -- This doesn't There are a couple routines I sent to RDS on the Recent Contributions Page that handles these problems. (I forgot to put my E-mail address in it, and there isn't any example code, oops :/ The code needs a little cleaning up too...) Although if you only use positive integers there won't be any problem..... (The usual case, which is why the Insert Periods routine has the same problems, which, BTW, my first attempts at adding commas had them too... :) (Hey, actually, that s_print() routine looks a lot like the add_commas() I posted on the mailing list quite a few months ago! :) _____________________________________________________________________ You don't need to buy Internet access to use free Internet e-mail. Get completely free e-mail from Juno at http://www.juno.com Or call Juno at (800) 654-JUNO [654-5866]