xcode - Retrieve Trash size as an int in cocoa app -


is possible cocoa app retrieve size of trash int. nstask correct method this?

there's no easy way this. although mac gui presents unified trash, there's not 1 thing trash. each volume can have separate trash , volumes can come , go.

also, can quite time-consuming calculate size of contents of folder, doesn't seem idea.

if want it, you'd enumerate of mounted volumes using -[nsfilemanager mountedvolumeurlsincludingresourcevaluesforkeys:options:], convert urls fsrefs using cfurlgetfsref(), volume reference number fsref using fsgetcataloginfo() passing kfscatinfovolume whichinfo, find trash each volume using fsfindfolder() passing ktrashfoldertype foldertype, convert resulting fsref url using cfurlcreatefromfsref(), create directory enumerator url using -[nsfilemanager enumeratoraturl:includingpropertiesforkeys:options:errorhandler: passing nsurltotalfileallocatedsizekey in keys array, enumerate through enumerator getting each item's nsurltotalfileallocatedsizekey nsnumber, , accumulating -unsignedlonglongvalues of nsnumbers.

it may easier enumerate volumes using fsgetvolumeinfo(), passing kfsinvalidvolumerefnum volume , index, starting @ 1, volumeindex. you'd pass kfsvolinfonone whichinfo. you'd increment index , repeat until returns nsverr. advantage gives volume reference number directly don't have go url fsref volume reference number. disadvantage 1 more old-style api. however, have no choice use apis because there's no substitute fsfindfolder() in above.

anyway, enumerate on volumes trash folders, have prepared encounter volumes don't have trash folders. example, network-mounted volumes don't.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

c++ - Accessing inactive union member and undefined behavior? -

php - Get uncommon values from two or more arrays -