mirror of
https://git.aramjonghu.nl/AramJonghu/file-organizer.git
synced 2026-06-06 17:48:23 +02:00
finished?
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 29 KiB |
Binary file not shown.
@@ -33,12 +33,10 @@ pub fn classify(name: []const u8) Category {
|
|||||||
for (entry.extensions) |ext| {
|
for (entry.extensions) |ext| {
|
||||||
const eicDocument = std.ascii.eqlIgnoreCase(extension, ext);
|
const eicDocument = std.ascii.eqlIgnoreCase(extension, ext);
|
||||||
if (eicDocument) {
|
if (eicDocument) {
|
||||||
std.debug.print("{s} found!\n", .{@tagName(entry.category)});
|
|
||||||
return entry.category;
|
return entry.category;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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, "..", .{ .iterate = true }); // change to root later
|
const dir = try cwd.openDir(io, ".", .{ .iterate = true }); // change to root later
|
||||||
defer dir.close(io);
|
defer dir.close(io);
|
||||||
|
|
||||||
var iterate = dir.iterate();
|
var iterate = dir.iterate();
|
||||||
|
|||||||
+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 {
|
pub fn organize(io: std.Io, dir: std.Io.Dir, name: []const u8) !void {
|
||||||
const category = classify.classify(name);
|
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) {
|
const dest = switch (category) {
|
||||||
.image => "Pictures",
|
.image => "Pictures",
|
||||||
.document => "Documents",
|
.document => "Documents",
|
||||||
@@ -17,4 +17,8 @@ fn ensureCategoryDir(io: std.Io, dir: std.Io.Dir, category: classify.Category) !
|
|||||||
};
|
};
|
||||||
|
|
||||||
try dir.createDirPath(io, dest);
|
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