-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from zigcc/0103
add 01-03
- Loading branch information
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//! File names that have been modified in the last 24 hours | ||
|
||
const std = @import("std"); | ||
const fs = std.fs; | ||
const print = std.debug.print; | ||
|
||
pub fn main() !void { | ||
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | ||
defer _ = gpa.deinit(); | ||
const allocator = gpa.allocator(); | ||
|
||
var iter_dir = try fs.cwd().openIterableDir(".", .{ | ||
.no_follow = true, // `true` means it won't dereference the symlinks. | ||
}); | ||
defer iter_dir.close(); | ||
|
||
var walker = try iter_dir.walk(allocator); | ||
defer walker.deinit(); | ||
|
||
const now = std.time.nanoTimestamp(); | ||
while (try walker.next()) |entry| { | ||
if (entry.kind != .file) { | ||
continue; | ||
} | ||
|
||
const file = try iter_dir.dir.openFile(entry.path, .{}); | ||
const md = try file.metadata(); | ||
const last_modified = md.modified(); | ||
const duration = now - last_modified; | ||
if (duration < std.time.ns_per_hour * 24) { | ||
print("Last modified: {d} seconds ago, read_only:{any}, size:{d} bytes, filename: {s}\n", .{ | ||
@divTrunc(duration, std.time.ns_per_s), | ||
md.permissions().readOnly(), | ||
md.size(), | ||
entry.path, | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# File names that have been modified in the last 24 hours | ||
|
||
```zig | ||
const std = @import("std"); | ||
const fs = std.fs; | ||
const print = std.debug.print; | ||
pub fn main() !void { | ||
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | ||
defer _ = gpa.deinit(); | ||
const allocator = gpa.allocator(); | ||
var iter_dir = try fs.cwd().openIterableDir(".", .{ | ||
.no_follow = true, // `true` means it won't dereference the symlinks. | ||
}); | ||
defer iter_dir.close(); | ||
var walker = try iter_dir.walk(allocator); | ||
defer walker.deinit(); | ||
const now = std.time.nanoTimestamp(); | ||
while (try walker.next()) |entry| { | ||
if (entry.kind != .file) { | ||
continue; | ||
} | ||
const file = try iter_dir.dir.openFile(entry.path, .{}); | ||
const md = try file.metadata(); | ||
const last_modified = md.modified(); | ||
const duration = now - last_modified; | ||
if (duration < std.time.ns_per_hour * 24) { | ||
print("Last modified: {d} seconds ago, read_only:{any}, size:{d} bytes, filename: {s}\n", .{ | ||
@divTrunc(duration, std.time.ns_per_s), | ||
md.permissions().readOnly(), | ||
md.size(), | ||
entry.path, | ||
}); | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters