Добавлены модули общего назначения
This commit is contained in:
parent
043c0b91f6
commit
e753c86eb9
8 changed files with 63 additions and 15 deletions
30
source/examples/common/isexists.d
Normal file
30
source/examples/common/isexists.d
Normal file
|
@ -0,0 +1,30 @@
|
|||
module examples.common.isexists;
|
||||
|
||||
import std.process : environment;
|
||||
import std.file : exists, isFile;
|
||||
import std.path : pathSeparator, buildPath;
|
||||
import std.array : split;
|
||||
import std.stdio : writefln;
|
||||
|
||||
// Проверка существования утилиты в PATH
|
||||
private bool isExecutableExists(string appName) {
|
||||
auto path = environment.get("PATH");
|
||||
if (path is null) return false;
|
||||
|
||||
foreach (dir; path.split(pathSeparator)) {
|
||||
auto fullPath = buildPath(dir, appName);
|
||||
if (exists(fullPath) && isFile(fullPath)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void isExists() {
|
||||
foreach (app; ["ls", "mc", "htop", "bash", "nano"]) {
|
||||
if (isExecutableExists(app))
|
||||
writefln("Приложение %s найдено", app);
|
||||
else
|
||||
writefln("Приложение %s не найдено", app);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue