Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Gtk;
- using GLib;
- private int64[] get_folder_data (File file, string space = "", Cancellable? cancellable = null) throws Error
- {
- FileEnumerator enumerator = file.enumerate_children (
- "standard::*",
- FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
- cancellable);
- int64 files = 0;
- int64 size = 0;
- int64[] data = new int64[2];
- FileInfo info = null;
- while (cancellable.is_cancelled () == false && ((info = enumerator.next_file (cancellable)) != null)) {
- if (info.get_file_type () == FileType.DIRECTORY) {
- File subdir = file.resolve_relative_path (info.get_name ());
- get_folder_data (subdir, space + " ", cancellable);
- } else {
- files += 1;//Sum Files
- size += info.get_size ();//Accumulates Size
- }
- }
- if (cancellable.is_cancelled ()) {
- throw new IOError.CANCELLED ("Operation was cancelled");
- }
- data[0] = files;
- data[1] = size;
- stdout.printf ("APT CACHE SIZE: %s\n", files.to_string());
- stdout.printf ("APT CACHE FILES: %s\n", size.to_string());
- return data;
- }
- public static int main (string[] args) {
- Gtk.init (ref args);
- File APT_CACHE_PATH = File.new_for_path ("/var/cache/apt/archives");
- try {
- get_folder_data (APT_CACHE_PATH, "", new Cancellable ());
- } catch (Error e) {
- stdout.printf ("ERROR: %s\n", e.message);
- }
- Gtk.main ();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement