mirror of
https://git.aramjonghu.nl/AramJonghu/file-organizer.git
synced 2026-06-07 21:58:24 +02:00
File checker can now check all types
This commit is contained in:
+31
-7
@@ -1,20 +1,44 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
pub const Category = enum { image, document, music, video, code, other };
|
pub const Category = enum {
|
||||||
|
image,
|
||||||
|
document,
|
||||||
|
music,
|
||||||
|
video,
|
||||||
|
code,
|
||||||
|
other,
|
||||||
|
};
|
||||||
|
|
||||||
|
const CategoryEntry = struct {
|
||||||
|
category: Category,
|
||||||
|
extensions: []const []const u8,
|
||||||
|
};
|
||||||
|
|
||||||
|
const CategoryMap = [_]CategoryEntry{
|
||||||
|
.{ .category = .image, .extensions = &ImageTypes },
|
||||||
|
.{ .category = .document, .extensions = &DocumentTypes },
|
||||||
|
.{ .category = .music, .extensions = &MusicTypes },
|
||||||
|
.{ .category = .video, .extensions = &VideoTypes },
|
||||||
|
};
|
||||||
|
|
||||||
|
const ImageTypes = [_][]const u8{ ".png", ".jpg", ".jpeg", ".webp", ".gif" };
|
||||||
const DocumentTypes = [_][]const u8{ ".pdf", ".docx", ".odt" };
|
const DocumentTypes = [_][]const u8{ ".pdf", ".docx", ".odt" };
|
||||||
|
const MusicTypes = [_][]const u8{ ".mp3", ".ogg", ".flac", ".opus", ".aac", ".wav", ".alac", ".m4a" };
|
||||||
|
const VideoTypes = [_][]const u8{ ".mp4", ".mkv", ".mov", ".m4v" };
|
||||||
|
|
||||||
pub fn classify(name: []const u8) Category {
|
pub fn classify(name: []const u8) Category {
|
||||||
const extension = std.fs.path.extension(name);
|
const extension = std.fs.path.extension(name);
|
||||||
|
|
||||||
for (DocumentTypes) |ext| {
|
for (CategoryMap) |entry| {
|
||||||
const eicDocument = std.ascii.eqlIgnoreCase(extension, ext);
|
for (entry.extensions) |ext| {
|
||||||
if (eicDocument) {
|
const eicDocument = std.ascii.eqlIgnoreCase(extension, ext);
|
||||||
std.debug.print("document found! \n", .{});
|
if (eicDocument) {
|
||||||
return .document;
|
std.debug.print("{s} found!\n", .{@tagName(entry.category)});
|
||||||
|
return entry.category;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std.debug.print("no document found! \n", .{});
|
std.debug.print("no compatible extensions found! \n", .{});
|
||||||
return .other;
|
return .other;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@ pub fn main() !void {
|
|||||||
|
|
||||||
const io = threaded.io();
|
const io = threaded.io();
|
||||||
const cwd = std.Io.Dir.cwd();
|
const cwd = std.Io.Dir.cwd();
|
||||||
const dir = try cwd.openDir(io, "examples", .{ .iterate = true });
|
const dir = try cwd.openDir(io, ".", .{ .iterate = true });
|
||||||
defer dir.close(io);
|
defer dir.close(io);
|
||||||
|
|
||||||
var it = dir.iterate();
|
var it = dir.iterate();
|
||||||
|
|||||||
Reference in New Issue
Block a user