2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,17 +1,32 @@
Write a program that will list everything in the current folder, similar to the Unix utility “<tt>ls</tt>” [http://man7.org/linux/man-pages/man1/ls.1.html] (or the Windows terminal command “<tt>DIR</tt>”). The output must be sorted, but printing extended details and producing multi-column output is not required.
;Task:
Write a program that will list everything in the current folder, &nbsp; similar to:
:::* &nbsp; the Unix utility &nbsp; “<tt>ls</tt>” &nbsp; [http://man7.org/linux/man-pages/man1/ls.1.html] &nbsp; &nbsp; &nbsp; or
:::* &nbsp; the Windows terminal command &nbsp; “<tt>DIR</tt>”
<br>
The output must be sorted, but printing extended details and producing multi-column output is not required.
;Example output
For the list of paths:
<pre>/foo/bar
<pre>
/foo/bar
/foo/bar/1
/foo/bar/2
/foo/bar/a
/foo/bar/b</pre>
/foo/bar/b
</pre>
When the program is executed in `/foo`, it should print:
<pre>bar</pre>
and when the program is executed in `/foo/bar`, it should print:
<pre>1
When the program is executed in &nbsp; `/foo`, &nbsp; it should print:
<pre>
bar
</pre>
and when the program is executed in &nbsp; `/foo/bar`, &nbsp; it should print:
<pre>
1
2
a
b</pre>
b
</pre>
<br><br>

View file

@ -0,0 +1,12 @@
(defun files-list (&optional (path "."))
(let* ((dir (concatenate 'string path "/"))
(abs-path (car (directory dir)))
(file-pattern (concatenate 'string dir "*"))
(subdir-pattern (concatenate 'string file-pattern "/")))
(remove-duplicates
(mapcar (lambda (p) (enough-namestring p abs-path))
(mapcan #'directory (list file-pattern subdir-pattern)))
:test #'string-equal)))
(defun ls (&optional (path "."))
(format t "~{~a~%~}" (sort (files-list path) #'string-lessp)))

View file

@ -0,0 +1,11 @@
iex(1)> ls = fn dir -> File.ls!(dir) |> Enum.each(&IO.puts &1) end
#Function<6.54118792/1 in :erl_eval.expr/5>
iex(2)> ls.("foo")
bar
:ok
iex(3)> ls.("foo/bar")
1
2
a
b
:ok

View file

@ -0,0 +1,18 @@
PROGRAM LS !Names the files in the current directory.
USE DFLIB !Mysterious library.
TYPE(FILE$INFO) INFO !With mysterious content.
NAMELIST /HIC/INFO !This enables annotated output.
INTEGER MARK,L !Assistants.
MARK = FILE$FIRST !Starting state.
Call for the next file.
10 L = GETFILEINFOQQ("*",INFO,MARK) !Mystery routine returns the length of the file name.
IF (MARK.EQ.FILE$ERROR) THEN !Or possibly, not.
WRITE (6,*) "Error!",L !Something went wrong.
WRITE (6,HIC) !Reveal INFO, annotated.
STOP "That wasn't nice." !Quite.
ELSE IF (IAND(INFO.PERMIT,FILE$DIR) .EQ. 0) THEN !Not a directory.
IF (L.GT.0) WRITE (6,*) INFO.NAME(1:L) !The object of the exercise!
END IF !So much for that entry.
IF (MARK.NE.FILE$LAST) GO TO 10 !Lastness is discovered after the last file is fingered.
END !If FILE$LAST is not reached, "system resources may be lost."

View file

@ -0,0 +1,16 @@
INTERFACE
INTEGER*4 FUNCTION GETFILEINFOQQ(FILES, BUFFER,dwHANDLE)
!DEC$ ATTRIBUTES DEFAULT :: GETFILEINFOQQ
CHARACTER*(*) FILES
STRUCTURE / FILE$INFO /
INTEGER*4 CREATION ! Creation time (-1 on FAT)
INTEGER*4 LASTWRITE ! Last write to file
INTEGER*4 LASTACCESS ! Last access (-1 on FAT)
INTEGER*4 LENGTH ! Length of file
INTEGER*2 PERMIT ! File access mode
CHARACTER*255 NAME ! File name
END STRUCTURE
RECORD / FILE$INFO / BUFFER
INTEGER*4 dwHANDLE
END FUNCTION
END INTERFACE

View file

@ -1,2 +1,2 @@
dir '*' NB. includes properties
> 1 dir '*' NB. plain filename as per task
dir '' NB. includes properties
>1 1 dir '' NB. plain filename as per task

View file

@ -0,0 +1,2 @@
require("lfs")
for file in lfs.dir(".") do print(file) end

View file

@ -0,0 +1,5 @@
opendir my $handle, '.' or die "Couldnt open current directory: $!";
while (readdir $handle) {
print "$_\n";
}
closedir $handle;

View file

@ -0,0 +1 @@
print "$_\n" for glob '*';

View file

@ -0,0 +1 @@
print "$_\n" for glob '* .*'; # If you want to include dot files

View file

@ -0,0 +1,2 @@
(for F (sort (dir))
(prinl F) )

View file

@ -0,0 +1,13 @@
files #f, DefaultDir$ + "\*.*" ' RunBasic Default directory.. Can be any directroy
print "rowcount: ";#f ROWCOUNT() ' how many rows in directory
#f DATEFORMAT("mm/dd/yy") 'set format of file date or not
#f TIMEFORMAT("hh:mm:ss") 'set format of file time or not
count = #f rowcount()
for i = 1 to count ' loop thru the row count
print "info: ";#f nextfile$() ' file info
print "name: ";#f NAME$() ' Name of file
print "size: ";#f SIZE() ' size
print "date: ";#f DATE$() ' date
print "time: ";#f TIME$() ' time
print "isdir: ";#f ISDIR() ' 1 = is a directory
next

View file

@ -0,0 +1,3 @@
variable d = listdir(getcwd()), p;
foreach p (array_sort(d))
() = printf("%s\n", d[p] );