TweetFollow Us on Twitter

Folder Clean-up
Volume Number:9
Issue Number:3
Column Tag:Useful Tricks

Related Info: File Manager File Mgr (PBxxx) Finder Interface

Clean up Your Folders

An app to arrange your finder windows

By Mike Scanlin, MacTech Magazine Regular Contributing Author

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

Isn’t it nice that the Developer CD has all of its directory windows nicely orgainized and arranged so that you can work your way down eight or nine levels deep and see at a glance the complete path to where you currently are? Wouldn’t it be nice if your gigabyte hard drive obeyed the same pretty convention? Well, here’s a little code fragment that will make that possible for you.

CleanUpFolders is a tiny app I wrote when the server volumes at my company were getting out of control. People with 96” monitors would put server directory windows all over the place so that when I opened them on my 16” screen they would either be minimally visible or in a place where the Finder put them because they would otherwise be off the screen entirely. Now we run CleanUpFolders on our server volumes about once a week and all is well. It positions and sizes all directory windows in a staggered fashion, as well as changes the view of each directory to View by Name and closes any open triangles it finds.

Before CleanUpFolders:

After CleanUpFolders:

Much nicer, eh? This program has no user interface whatsoever. You just launch it and when it returns your windows are consistently sized and positioned. You can change the size, position and offset of the windows by editing the source code and recompiling. I know, it’s somewhat crude, but MacTech readers don’t want to read two pages of interface and event handling fluff just to get to the 20 lines of code that actually does something, do they? I thought so.

After you run CleanUpFolders you will have to close all your windows and then reopen them before you see its effects (because the Finder doesn’t resize an open window when you call PBSetCatInfo on it, but it will use the new size if you close and then reopen the window). Have fun.

Listing CleanUpYourFolders.c
/*****************************************************
 * CleanUpFolders
 *
 * A little app to clean up all folders' windows
 * starting with the one that this app is in and
 * continuing recursively downwards.
 *
 * Mike Scanlin  17 Oct 1992
 ****************************************************/

#define kFolderBit (1 << 4)
#define kZoomBit 0x0020
#define kOpenTriangleBit  0x0010
#define kViewMask0xFF00
#define kViewByName0x0200

void main(void);
void CleanUpAFolder(long theDrDirID);
void EnumerateCatalog(long dirID);

CInfoPBRectheCPB;
Str255  theName;
Rect    theRect;
short   hOffset, vOffset;


/*****************************************************
 * main
 * 
 * Clean up the directory that this app is residing
 * in and then all of the directories contained within
 * this directory recursively. Put this app in the 
 * root directory of a volume and launch it to clean 
 * up the entire volume.
 ****************************************************/
void main()
{
 long   dirID;
 short  vRefNum;
 
 /* Set the initial directory's size and position */
 SetRect(&theRect, 2, 40, 2+228, 40+165);
 
 /* Set the offset for each child directory */
 hOffset = 16;
 vOffset = 16;
 
 /* Find out where this app is located */
 HGetVol(&theName, &vRefNum, &dirID);

 theCPB.dirInfo.ioVRefNum = vRefNum;
 theCPB.dirInfo.ioNamePtr = theName;
 
 /* First, clean up the current directory */
 theCPB.hFileInfo.ioFDirIndex = -1;
 theCPB.dirInfo.ioDrDirID = dirID;
 PBGetCatInfo(&theCPB, FALSE);
 CleanUpAFolder(theCPB.dirInfo.ioDrParID);
 
 /* Now clean up all child directories */
 EnumerateCatalog(dirID);
}


/*****************************************************
 * CleanUpAFolder
 * 
 * Given a directory ID, this will unzoom the
 * window, size and position the window, close the
 * "triangle" and set the view to View by Name.
 ****************************************************/
void CleanUpAFolder(long theDrDirID)
{
 theCPB.dirInfo.ioDrDirID = theDrDirID;
 theCPB.dirInfo.ioDrUsrWds.frRect = theRect;
 /* clear the zoomed bit, the "open triangle bit"
  * and the view; leave the other bits alone
  * because we don't know what they're for.
  */
 theCPB.dirInfo.ioDrUsrWds.frView &=
 ~kViewMask - kZoomBit - kOpenTriangleBit;
 /* set the view to View by Name */
 theCPB.dirInfo.ioDrUsrWds.frView |= kViewByName;
 PBSetCatInfo(&theCPB, FALSE);
}


/*****************************************************
 * EnumerateCatalog
 *
 * Given a directory ID to start with, this calls
 * CleanUpAFolder once for every directory within
 * the given start directory. On entry it offsets
 * theRect down and to the right; on exit it offsets
 * it up and to the left.
 ****************************************************/
void EnumerateCatalog(long dirID)
{
 long   tempDir;
 short  index;
 OSErr  myErr;
 
 OffsetRect(&theRect, hOffset, vOffset);

 index = 1;
 do {
 theCPB.hFileInfo.ioFDirIndex = index;
 theCPB.dirInfo.ioDrDirID = dirID;
 myErr = PBGetCatInfo(&theCPB, FALSE);
 if (myErr == noErr) {
 if (theCPB.hFileInfo.ioFlAttrib & kFolderBit) {
 tempDir = theCPB.dirInfo.ioDrDirID;
 CleanUpAFolder(dirID);
 EnumerateCatalog(tempDir);
 myErr = noErr;
 }
 }
 index++;
 } while (myErr == noErr);

 OffsetRect(&theRect, -hOffset, -vOffset);
}

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Bartender 3.0.32 - Organize your menu-ba...
Bartender lets you organize your menu-bar apps by hiding them, rearranging them, or moving them to Bartender's Bar. You can display the full menu bar, set options to have menu-bar items show in the... Read more
Adobe Animate CC 2018 18.0.1.115 - Anima...
Animate CC 2018 is available as part of Adobe Creative Cloud for as little as $19.99/month (or $9.99/month if you're a previous Flash Professional customer). Animate CC 2018 (was Flash CC) lets you... Read more
Adobe Lightroom Classic CC 7.1 - Import,...
Adobe Lightroom is available as part of Adobe Creative Cloud for as little as $9.99/month bundled with Photoshop CC as part of the photography package. Lightroom 6 is also available for purchase as a... Read more
ExpanDrive 6.1.8 - Access cloud storage...
ExpanDrive builds cloud storage in every application, acts just like a USB drive plugged into your Mac. With ExpanDrive, you can securely access any remote file server directly from the Finder or... Read more
ExpanDrive 6.1.8 - Access cloud storage...
ExpanDrive builds cloud storage in every application, acts just like a USB drive plugged into your Mac. With ExpanDrive, you can securely access any remote file server directly from the Finder or... Read more
DiskCatalogMaker 7.2.7 - Catalog your di...
DiskCatalogMaker is a simple disk management tool which catalogs disks. Simple, light-weight, and fast Finder-like intuitive look and feel Super-fast search algorithm Can compress catalog data for... Read more
DiskCatalogMaker 7.2.7 - Catalog your di...
DiskCatalogMaker is a simple disk management tool which catalogs disks. Simple, light-weight, and fast Finder-like intuitive look and feel Super-fast search algorithm Can compress catalog data for... Read more
Iridient Developer 3.2.1 - Powerful imag...
Iridient Developer (was RAW Developer) is a powerful image-conversion application designed specifically for OS X. Iridient Developer gives advanced photographers total control over every aspect of... Read more
BusyContacts 1.2.7 - Fast, efficient con...
BusyContacts is a contact manager for OS X that makes creating, finding, and managing contacts faster and more efficient. It brings to contact management the same power, flexibility, and sharing... Read more
MegaSeg 6.0.5 - Professional DJ and radi...
MegaSeg is a complete solution for pro audio/video DJ mixing, radio automation, and music scheduling with rock-solid performance and an easy-to-use design. Mix with visual waveforms and Magic... Read more

Latest Forum Discussions

See All

The best deals on the App Store this wee...
A new week means new discounts on the App Store. This week's deals run the gamut of action-adventure titles, puzzle games, and one of the best narrative adventure series out there. If you're looking to fill out your mobile gaming library on a... | Read more »
What you need to know about Animal Cross...
We hope you've been hard at work on collecting all of those holiday items in Animal Crossing: Pocket Camp, because you're about to get a whole new list of fun things to do as the game receives its first big update sometime soon. There are a lot of... | Read more »
Reigns: Her Majesty guide - how to use e...
Ruling a kingdom isn't easy--doubly so for a queen whose every decision is questioned by the other factions seeking a slice of power. Reigns: Her Majesty builds on the original game's swipey tactics, adding items that you can use to move the story... | Read more »
The best new games we played this week -...
Friday has crept up on us once again, so it's time to honor the best new games we've played over the past few days. This past week was a pretty exciting one, with the debut of lots of beautiful new indies and some familiar faces returning to the... | Read more »
Portal Knights guide- beginner tips and...
Portal Knights is finally making the jump to iOS and Android, and it's already climbing the ranks to become the next big MMO experience on mobile. This sprawling sandbox game will let you pursue any adventure you wish, whether you want to sling... | Read more »
Reigns: Her Majesty guide - how to swipe...
Reigns: Her Majesty is storming the App Store this week, bringing more tinder-esque kingdom building to eager players everywhere. If you've played the original Reigns, you'll know that leading a kingdom is never easy. It's a careful balancing act... | Read more »
Getting Over It (Games)
Getting Over It 1.0 Device: iOS Universal Category: Games Price: $4.99, Version: 1.0 (iTunes) Description: A game I madeFor a certain kind of person To hurt them. • Climb up an enormous mountain with nothing but a hammer and a pot.•... | Read more »
Reigns: Her Majesty (Games)
Reigns: Her Majesty 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: | Read more »
Pocket Legends Adventures guide - how to...
Pocket Legends Adventures is a fun action adventure RPG that takes control when you want it to, but also opens itself for player input, too, if you're looking to tkae a more active role in combat. Regardless of play style, the game can be quite... | Read more »
Portal Knights (Games)
Portal Knights 1.2.4 Device: iOS Universal Category: Games Price: $4.99, Version: 1.2.4 (iTunes) Description: Craft your adventure. Forge your hero. Become the ultimate Portal Knight! | Read more »

Price Scanner via MacPrices.net

Apple Watch Series 2, Certified Refurbished,...
Apple has Certified Refurbished Apple Watch Nike+ Series 2s, 42mm Space Gray Aluminum Case with Anthracite/Black Nike Sport Bands, available for $249 (38mm) or $279 (42mm). The 38mm model was out of... Read more
Apple offers Certified Refurbished 2016 12″ R...
Apple has Certified Refurbished 2016 12″ Retina MacBooks available starting at $949. Apple will include a standard one-year warranty with each MacBook, and shipping is free. The following... Read more
B&H drops price on 13″ 256GB MacBook Air...
B&H has the 13″ 1.8GHz/256GB Apple MacBook Air (MQD42LL/A) now on sale for $1079 including free shipping plus NY & NJ sales tax only. Their price is $120 off MSRP, and it’s the lowest price... Read more
Holiday sale: 9″ iPads starting at $299, take...
MacMall has 9″ WiFi iPads on sale for $30 off including free shipping: – 9″ 32GB WiFi iPad: $299 – 9″ 128GB WiFi iPad: $399 Read more
Green Monday deal: 15″ 2.8GHz MacBook Pro on...
B&H Photo has the 15″ 2.8GHz Space Gray MacBook Pro on sale for $250 off MSRP for today only as part of their Green Monday/Holiday sale. Shipping is free, and B&H charges sales tax for NY... Read more
Green Monday sale: B&H offers 12″ Apple i...
B&H Photo has 12″ iPad Pros on sale for up to $150 off MSRP as part of their Green Monday/Holiday sale. Shipping is free, and B&H charges sales tax in NY & NJ only: – 12″ 64GB WiFi iPad... Read more
Holiday deal: 21″ and 27″ Apple iMacs on sale...
MacMall has 2017 21″ and 27″ Apple iMacs on sale for up to $200 off MSRP. Shipping is free: – 21″ 2.3GHz iMac: $999 $100 off MSRP – 21″ 3.0GHz iMac: $1199 $100 off MSRP – 21″ 3.4GHz iMac: $1379 $120... Read more
Holiday deal: Apple Mac minis for up to $150...
MacMall has Mac minis on sale for up to $100 off MSRP, each including free shipping: – 1.4GHz Mac mini: $399 $100 off MSRP – 2.6GHz Mac mini: $599 $100 off MSRP – 2.8GHz Mac mini: $949 $50 off MSRP... Read more
Beats by Dr. Dre – BeatsX Earphones on sale f...
Best Buy has BeatsX Earphones on sale for $109, $40 off, on their online store. Sale price for online orders only. Choose free store pickup, if available, or choose free shipping. Read more
10″ 64GB WiFi Apple iPad Pros on sale for $59...
MacMall has 10.5″ 64GB Apple iPad Pros on sale for $599 including free shipping. That’s $50 off MSRP and among the lowest prices available for these iPads from any Apple reseller. Read more

Jobs Board

*Apple* Retail - Multiple Positions - Apple,...
Job Description:SalesSpecialist - Retail Customer Service and SalesTransform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
*Apple* Retail - Multiple Positions - Apple,...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
*Apple* Retail - Multiple Positions - Apple,...
Job Description:SalesSpecialist - Retail Customer Service and SalesTransform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
*Apple* Information Security - Security Data...
# Apple Information Security - Security Data Analyst Job Number: 113119545 Austin, Texas, United States Posted: 10-Nov-2017 Weekly Hours: 40.00 **Job Summary** This Read more
*Apple* Retail - Multiple Positions - Apple,...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.