2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -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, 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>”
|
||||
|
||||
<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 `/foo`, it should print:
|
||||
<pre>
|
||||
bar
|
||||
</pre>
|
||||
and when the program is executed in `/foo/bar`, it should print:
|
||||
<pre>
|
||||
1
|
||||
2
|
||||
a
|
||||
b</pre>
|
||||
b
|
||||
</pre>
|
||||
<br><br>
|
||||
|
|
|
|||
12
Task/Unix-ls/Common-Lisp/unix-ls.lisp
Normal file
12
Task/Unix-ls/Common-Lisp/unix-ls.lisp
Normal 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)))
|
||||
11
Task/Unix-ls/Elixir/unix-ls.elixir
Normal file
11
Task/Unix-ls/Elixir/unix-ls.elixir
Normal 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
|
||||
18
Task/Unix-ls/Fortran/unix-ls-1.f
Normal file
18
Task/Unix-ls/Fortran/unix-ls-1.f
Normal 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."
|
||||
16
Task/Unix-ls/Fortran/unix-ls-2.f
Normal file
16
Task/Unix-ls/Fortran/unix-ls-2.f
Normal 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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
2
Task/Unix-ls/Lua/unix-ls.lua
Normal file
2
Task/Unix-ls/Lua/unix-ls.lua
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
require("lfs")
|
||||
for file in lfs.dir(".") do print(file) end
|
||||
5
Task/Unix-ls/Perl/unix-ls-1.pl
Normal file
5
Task/Unix-ls/Perl/unix-ls-1.pl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
opendir my $handle, '.' or die "Couldnt open current directory: $!";
|
||||
while (readdir $handle) {
|
||||
print "$_\n";
|
||||
}
|
||||
closedir $handle;
|
||||
1
Task/Unix-ls/Perl/unix-ls-2.pl
Normal file
1
Task/Unix-ls/Perl/unix-ls-2.pl
Normal file
|
|
@ -0,0 +1 @@
|
|||
print "$_\n" for glob '*';
|
||||
1
Task/Unix-ls/Perl/unix-ls-3.pl
Normal file
1
Task/Unix-ls/Perl/unix-ls-3.pl
Normal file
|
|
@ -0,0 +1 @@
|
|||
print "$_\n" for glob '* .*'; # If you want to include dot files
|
||||
2
Task/Unix-ls/PicoLisp/unix-ls.l
Normal file
2
Task/Unix-ls/PicoLisp/unix-ls.l
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(for F (sort (dir))
|
||||
(prinl F) )
|
||||
13
Task/Unix-ls/Run-BASIC/unix-ls.run
Normal file
13
Task/Unix-ls/Run-BASIC/unix-ls.run
Normal 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
|
||||
3
Task/Unix-ls/S-lang/unix-ls.slang
Normal file
3
Task/Unix-ls/S-lang/unix-ls.slang
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
variable d = listdir(getcwd()), p;
|
||||
foreach p (array_sort(d))
|
||||
() = printf("%s\n", d[p] );
|
||||
Loading…
Add table
Add a link
Reference in a new issue