Smlnj rephrased question for listdir(filename, directoryname)

smlnj

i am a newbie learning sml and the question i am thrown with involves IO functions that i have no idea how it works even after reading it. Here is the 2 questions that i really need help with to get me started, please provide me with codings and some explaination, i will be able to trial and error with the code given for the other questions.

Q1) listdir(filename,directoryname), which given the name of a directory, list its contents in a text file. The listing is in a form that makes it easy to seperate filenames, dates and sizes from each other. (similar to what msdos does with "dir" but instead of just listing it out, it places all the files and details into a text file.

Q2) readlist(filename) which reads a list of filenames (each of which were produced by listdir in (Q1) and combines them into one large list. (reads from the text file in Q1 and then assigning the contents into 1 big list containing all the information)

Thing is, i only learned from the lecturer in school on the introduction section, there isnt even a system input or output example shown, not even the "use file" function is taught. if anyone that knows sml sees this, please help. Thanks to anyone who took the effort helping me.

Thanks for the reply, current I am using SMLNJ to try and do this. Basically, Q1 requires me to list the directory's files of the "directoryname" provided into a text file in "filename". The Q2 requires me to read from the "filename" text file and then place the contents into one large list.

Duplicate of: smlnj listdir

Best Answer

As a hint I will say that you have to make use of these functions:

OS.FileSys.OpenDir(directoryname) - this will open directory stream for you (Q1) TextIO.openOut(filename) - this will open the file stream (Q2)

TextIO.openIn(filename)- this will open the file (Q2) If you are stuck and dont' know how to do the progs then I will post the full code here, but i suggest you first give a try.


zubair sheikh

Related Topic