+
+ # Change the current working directory
+ #
+ # "/etc".chdir
+ # assert getcwd == "/etc"
+ # "..".chdir
+ # assert getcwd == "/"
+ #
+ # TODO: errno
+ fun chdir do to_cstring.file_chdir
+
+ # Return right-most extension (without the dot)
+ #
+ # Only the last extension is returned.
+ # There is no special case for combined extensions.
+ #
+ # assert "file.txt".file_extension == "txt"
+ # assert "file.tar.gz".file_extension == "gz"
+ #
+ # For file without extension, `null` is returned.
+ # Hoever, for trailing dot, `""` is returned.
+ #
+ # assert "file".file_extension == null
+ # assert "file.".file_extension == ""
+ #
+ # The starting dot of hidden files is never considered.
+ #
+ # assert ".file.txt".file_extension == "txt"
+ # assert ".file".file_extension == null
+ fun file_extension: nullable String
+ do
+ var last_slash = chars.last_index_of('.')
+ if last_slash > 0 then
+ return substring( last_slash+1, length )
+ else
+ return null
+ end
+ end
+
+ # returns files contained within the directory represented by self
+ fun files : Set[ String ] is extern import HashSet[String], HashSet[String].add, NativeString.to_s, String.to_cstring, HashSet[String].as(Set[String]) `{
+ char *dir_path;
+ DIR *dir;
+
+ dir_path = String_to_cstring( recv );
+ if ((dir = opendir(dir_path)) == NULL)
+ {
+ perror( dir_path );
+ exit( 1 );
+ }
+ else
+ {
+ HashSet_of_String results;
+ String file_name;
+ struct dirent *de;
+
+ results = new_HashSet_of_String();
+
+ while ( ( de = readdir( dir ) ) != NULL )
+ if ( strcmp( de->d_name, ".." ) != 0 &&
+ strcmp( de->d_name, "." ) != 0 )
+ {
+ file_name = NativeString_to_s( strdup( de->d_name ) );
+ HashSet_of_String_add( results, file_name );
+ }
+
+ closedir( dir );
+ return HashSet_of_String_as_Set_of_String( results );
+ }
+ `}