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

@ -0,0 +1,32 @@
# returns TRUE if the specified directory is empty, FALSE if it doesn't exist or is non-empty #
PROC is empty directory = ( STRING directory )BOOL:
IF NOT file is directory( directory )
THEN
# directory doesn't exist #
FALSE
ELSE
# directory is empty if it contains no files or just "." and possibly ".." #
[]STRING files = get directory( directory );
BOOL result := FALSE;
FOR f FROM LWB files TO UPB files
WHILE result := files[ f ] = "." OR files[ f ] = ".."
DO
SKIP
OD;
result
FI # is empty directory # ;
# test the is empty directory procedure #
# show whether the directories specified on the command line ( following "-" ) are empty or not #
BOOL directory name parameter := FALSE;
FOR i TO argc DO
IF argv( i ) = "-"
THEN
# marker to indicate directory names follow #
directory name parameter := TRUE
ELIF directory name parameter
THEN
# have a directory name - report whether it is emty or not #
print( ( argv( i ), " is ", IF is empty directory( argv( i ) ) THEN "empty" ELSE "not empty" FI, newline ) )
FI
OD

View file

@ -0,0 +1,16 @@
function scandir(directory)
local i, t, popen = 0, {}, io.popen
local pfile = popen('ls -a "'..directory..'"')
for filename in pfile:lines() do
if filename ~= '.' and filename ~= '..' then
i = i + 1
t[i] = filename
end
end
pfile:close()
return t
end
function isemptydir(directory)
return #scandir(directory) == 0
end

View file

@ -0,0 +1,8 @@
function isemptydir(directory,nospecial)
for filename in require('lfs').dir(directory) do
if filename ~= '.' and filename ~= '..' then
return false
end
end
return true
end

View file

@ -0,0 +1,3 @@
function : IsEmptyDirectory(dir : String) ~ Bool {
return Directory->List(dir)->Size() = 0;
}

View file

@ -0,0 +1 @@
chkdir(d)=extern(concat(["[ -d '",d,"' ]&&ls -A '",d,"'|wc -l||echo -1"]))

View file

@ -0,0 +1 @@
dir_is_empty(d)=!chkdir(d)

View file

@ -0,0 +1,12 @@
fun isDirEmpty(path: string) =
let
val dir = OS.FileSys.openDir path
val dirEntryOpt = OS.FileSys.readDir dir
in
(
OS.FileSys.closeDir(dir);
case dirEntryOpt of
NONE => true
| _ => false
)
end;