mirror of
https://git.aramjonghu.nl/AramJonghu/file-organizer.git
synced 2026-06-07 01:48:24 +02:00
finished?
This commit is contained in:
+6
-2
@@ -3,10 +3,10 @@ const classify = @import("classify.zig");
|
||||
|
||||
pub fn organize(io: std.Io, dir: std.Io.Dir, name: []const u8) !void {
|
||||
const category = classify.classify(name);
|
||||
try ensureCategoryDir(io, dir, category);
|
||||
try placeFile(io, dir, category, name);
|
||||
}
|
||||
|
||||
fn ensureCategoryDir(io: std.Io, dir: std.Io.Dir, category: classify.Category) !void {
|
||||
fn placeFile(io: std.Io, dir: std.Io.Dir, category: classify.Category, name: []const u8) !void {
|
||||
const dest = switch (category) {
|
||||
.image => "Pictures",
|
||||
.document => "Documents",
|
||||
@@ -17,4 +17,8 @@ fn ensureCategoryDir(io: std.Io, dir: std.Io.Dir, category: classify.Category) !
|
||||
};
|
||||
|
||||
try dir.createDirPath(io, dest);
|
||||
|
||||
var buf: [std.fs.max_path_bytes]u8 = undefined;
|
||||
const path = try std.fmt.bufPrint(&buf, "{s}/{s}", .{ dest, name });
|
||||
try dir.rename(name, dir, path, io);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user