Unix/ls: Difference between revisions

(Added XPL0 example.)
Line 1,303:
say file;
}</lang>
 
=={{header|Smalltalk}}==
cheating solution:
{{works with|Smalltalk/X}}
<lang smalltalk>Transcript showCR: ( PipeStream outputFromCommand:'ls -l' )</lang>
real solution:
{{works with|Smalltalk/X}}
<lang smalltalk>dir := '.' asFilename.
dir directoryContentsAsFilenames sort do:[:fn |
"/ generate a line of the form (loke ls -l):
"/ drwxrwxrwx user group size date time name
line := String streamContents:[:s |
|accessRights|
 
s nextPut:(fn isDirectory ifTrue:[$d] ifFalse:[$-]).
accessRights := fn symbolicAccessRights.
#( readUser writeUser executeUser
readGroup writeGroup executeGroup
readOthers writeOthers executeOthers
)
with:'rwxrwxrwx'
do:[:eachRight :charToPrint |
s nextPut:((accessRights includes:eachRight) ifTrue:[charToPrint] ifFalse:[$-])
].
(OperatingSystem getUserNameFromID:fn info uid) printOn:s leftPaddedTo:10.
(OperatingSystem getGroupNameFromID:fn info gid) printOn:s leftPaddedTo:10.
fn fileSize printOn:s leftPaddedTo:12.
fn modificationTime year = Date today year ifTrue:[
fn modificationTime printOn:s format:' %(dayPadded) %(ShortMonthName) %h:%m'.
] ifFalse:[
fn modificationTime asDate printOn:s format:' %(dayPadded) %(ShortMonthName) %y'.
].
s space.
s nextPutAll:fn baseName
].
Transcript showCR:line
].</lang>
 
=={{header|Standard ML}}==
Anonymous user