September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,37 @@
# syntax: GAWK -f EMPTY_DIRECTORY.AWK
BEGIN {
n = split("C:\\TEMP3,C:\\NOTHERE,C:\\AWK\\FILENAME,C:\\WINDOWS",arr,",")
for (i=1; i<=n; i++) {
printf("'%s' %s\n",arr[i],is_dir(arr[i]))
}
exit(0)
}
function is_dir(path, cmd,dots,entries,msg,rec,valid_dir) {
cmd = sprintf("DIR %s 2>NUL",path) # MS-Windows
while ((cmd | getline rec) > 0) {
if (rec ~ /[0-9]:[0-5][0-9]/) {
if (rec ~ / (\.|\.\.)$/) { # . or ..
dots++
continue
}
entries++
}
if (rec ~ / Dir\(s\) .* bytes free$/) {
valid_dir = 1
}
}
close(cmd)
if (valid_dir == 0) {
msg = "does not exist"
}
else if (valid_dir == 1 && entries == 0) {
msg = "is an empty directory"
}
else if (dots == 0 && entries == 1) {
msg = "is a file"
}
else {
msg = sprintf("is a directory with %d entries",entries)
}
return(msg)
}

View file

@ -0,0 +1,19 @@
' empty directory test
somedir$ = "somedir"
files = testdir(somedir$)
IF files = 0 THEN PRINT somedir$, " directory empty"
files = testdir(".")
PRINT "Current directory holds ", files, " files"
END
FUNCTION testdir(somedir$)
OPEN somedir$ FOR DIRECTORY AS adir
total = 0
REPEAT
GETFILE afile$ FROM adir
IF afile$ != "." AND afile$ != ".." AND afile$ != "" THEN INCR total
UNTIL ISFALSE(LEN(afile$))
IF (long)adir != 0 THEN CLOSE DIRECTORY adir
RETURN total
END FUNCTION

View file

@ -0,0 +1,12 @@
Public Sub Main()
Dim sFolder As String = User.home &/ "Rosetta"
Dim sDir As String[] = Dir(sFolder)
Dim sTemp As String
Dim sOutput As String = sfolder & " is NOT empty"
Try sTemp = sDir[0]
If Error Then sOutput = sfolder & " is empty"
Print sOutput
End

View file

@ -0,0 +1,5 @@
# v0.6.0
isemptydir(dir::AbstractString) = isempty(readdir(dir))
@show isemptydir(".")
@show isemptydir("/home")

View file

@ -0,0 +1,9 @@
// version 1.1.4
import java.io.File
fun main(args: Array<String>) {
val dirPath = "docs" // or whatever
val isEmpty = (File(dirPath).list().isEmpty())
println("$dirPath is ${if (isEmpty) "empty" else "not empty"}")
}

View file

@ -0,0 +1,3 @@
emptydirectory := proc (dir)
is(listdir(dir) = [".", ".."]);
end proc;

View file

@ -0,0 +1,20 @@
Call test 'D:\nodir' /* no such directory */
Call test 'D:\edir' /* an empty directory */
Call test 'D:\somedir' /* directory with 2 files */
Call test 'D:\somedir','S' /* directory with 3 files */
Exit
test: Parse Arg fd,nest
If SysIsFileDirectory(fd)=0 Then
Say 'Directory' fd 'not found'
Else Do
ret=SysFileTree(fd'\*.*','X', 'F'nest)
If x.0=0 Then
say 'Directory' fd 'is empty'
Else Do
If nest='' Then
say 'Directory' fd 'contains' x.0 'files'
Else
say 'Directory' fd 'contains' x.0 'files (some nested)'
End
End
Return

View file

@ -0,0 +1,27 @@
procedure test(string filename)
string msg
switch get_file_type(filename) do
case FILETYPE_UNDEFINED: msg = "is UNDEFINED"
case FILETYPE_NOT_FOUND: msg = "is NOT_FOUND"
case FILETYPE_FILE: msg = "is a FILE"
case FILETYPE_DIRECTORY:
sequence d = dir(filename)
integer count = 0
for i=1 to length(d) do
if not find(d[i][D_NAME],{".",".."}) then
count += 1
end if
end for
if count=0 then
msg = "is an empty directory"
else
msg = sprintf("is a directory containing %d files",{count})
end if
end switch
printf(1,"%s %s\n",{filename,msg})
end procedure
constant tests = {"C:\\xx","C:\\not_there","C:\\Program Files (x86)\\Phix\\p.exe","C:\\Windows"}
for i=1 to length(tests) do
test(tests[i])
end for

View file

@ -1,5 +0,0 @@
# Checks if a directory is empty, but raises SystemCallError
# if _path_ is not a directory.
def empty_dir?(path)
not Dir.foreach(path).detect {|f| f != '.' and f != '..'}
end

View file

@ -1,8 +0,0 @@
# Checks if a directory is empty, but raises SystemCallError
# if _path_ is not a directory.
def empty_dir?(path)
Dir.foreach(path) {|f|
return false if f != '.' and f != '..'
}
return true
end

View file

@ -0,0 +1,3 @@
path:="Empty"; File.isDir(path).println();
File.mkdir(path); File.isDir(path).println();
File.glob(path+"/*").println(); // show contents of directory