Re: difficulty with dir()
- Posted by DerekParnell (admin) Oct 18, 2009
- 1021 views
Kat said...
Some time in the last 15 years, i made a directory name with a 16bit unicode char in it. I can open the file in text editors, in FF and IE, but dir() in a Eu program tells me it isn't there.
I just tried to do the same thing and its working fine.
I created a folder called "some « folder" and then a text file inside that called "test.data". I then wrote the following program and it works exactly as I expected it to.
include std/filesys.e object d sequence n = "c:\\temp\\some « folder" d = dir(n) for i = 1 to length(d) do printf(1, "%-40s %s\n", {d[i][D_NAME], d[i][D_ATTRIBUTES]}) if find('d', d[i][D_ATTRIBUTES]) then continue end if integer fh = open(n & '\\' & d[i][D_NAME], "r") object l integer cnt = 0 while sequence(l) with entry do cnt += 1 if l[$] = '\n' then l = l[1..$-1] end if printf(1, "%04d '%s'\n", {cnt, l}) entry l = gets(fh) end while close(fh) puts(1, "\n") end for
Output...
c:\temp>dir Volume in drive C has no label. Volume Serial Number is B872-CDD3 Directory of c:\temp 19/10/2009 09:54 AM <DIR> . 19/10/2009 09:54 AM <DIR> .. 19/10/2009 09:54 AM <DIR> Some « folder 19/10/2009 09:49 AM 527 test.ex 1 File(s) 527 bytes 3 Dir(s) 23,578,501,120 bytes free c:\temp>type test.ex include std/filesys.e object d sequence n = "c:\\temp\\some ½ folder" d = dir(n) for i = 1 to length(d) do printf(1, "%-40s %s\n", {d[i][D_NAME], d[i][D_ATTRIBUTES]}) if find('d', d[i][D_ATTRIBUTES]) then continue end if integer fh = open(n & '\\' & d[i][D_NAME], "r") object l integer cnt = 0 while sequence(l) with entry do cnt += 1 if l[$] = '\n' then l = l[1..$-1] end if printf(1, "%04d '%s'\n", {cnt, l}) entry l = gets(fh) end while close(fh) puts(1, "\n") end for c:\temp>eui test . d .. d test.data a 0001 'Line one in test data' 0002 ' another line' 0003 ' ' 0004 ' and yet another line.' 0005 '' 0006 'last line' c:\temp>