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);
}

 
AAPL
$101.32
Apple Inc.
+0.74
MSFT
$45.15
Microsoft Corpora
-0.07
GOOG
$582.56
Google Inc.
-0.81

MacTech Search:
Community Search:

Software Updates via MacUpdate

calibre 2.0.0 - Complete e-library manag...
Calibre is a complete e-book library manager. Organize your collection, convert your books to multiple formats, and sync with all of your devices. Let Calibre be your multi-tasking digital... Read more
Apple iMovie 10.0.5 - Edit personal vide...
With an all-new design, Apple iMovie lets you enjoy your videos like never before. Browse your clips more easily, instantly share your favorite moments, and create beautiful HD movies and Hollywood-... Read more
Apple Keynote 6.2.2 - Apple's prese...
Apple Keynote makes it simple to create and deliver beautiful presentations. Powerful tools and dazzling effects bring your ideas to life. You can work seamlessly between Mac and iOS devices. And... Read more
Apple Numbers 3.2.2 - Apple's sprea...
With Apple Numbers, sophisticated spreadsheets are just the start. The whole sheet is your canvas. Just add dramatic interactive charts, tables, and images that paint a revealing picture of your data... Read more
OpenOffice 4.1.1 - Free and open-source...
OpenOffice.org is both an Open Source product and a project. The product is a multi-platform office productivity suite. It includes the key desktop applications, such as a word processor,... Read more
Pages 5.2.2 - Apple's word processo...
Apple Pages is a powerful word processor that gives you everything you need to create documents that look beautiful. And read beautifully. It lets you work seamlessly between Mac and iOS devices. And... Read more
Quicken 2015 2.0.1 - Complete personal f...
The new Quicken 2015 helps you manage all your personal finances in one place, so you can see where you're spending and where you can save. Quicken automatically categorizes your financial... Read more
CleanMyMac 2.2.7 - Delete files that was...
CleanMyMac makes space for the things you love. Sporting a range of ingenious new features, CleanMyMac 2 lets you safely and intelligently scan and clean your entire system, delete large, unused... Read more
MacFamilyTree 7.2.4 - Create and explore...
MacFamilyTree gives genealogy a facelift: it's modern, interactive, incredibly fast, and easy to use. We're convinced that generations of chroniclers would have loved to trade in their genealogy... Read more
Videobox 4.1.1 - Download Flash video th...
Videobox allows you to quickly and easily download Flash video from most all of the popular video sites on the internet. Videobox will convert the video into a native Quicktime format so it's ready... Read more

Latest Forum Discussions

See All

Trolls vs Vikings Update Adds Over One H...
Trolls vs Vikings Update Adds Over One Hundred Levels, Reduces Item Cost, and More Posted by Ellis Spice on August 22nd, 2014 [ permalink ] | Read more »
SNK Celebrates the 20th Anniversary of T...
SNK Celebrates the 20th Anniversary of The King of Fighters With a Big Sale Posted by Ellis Spice on August 22nd, 2014 [ permalink ] | Read more »
It Came From Canada: Star Wars: Commande...
With a brand new Star Wars trilogy on the horizon, prepare yourselves for Disney and George Lucas’s space fantasy throwback to be more omnipresent than ever before. So it should come as no surprise that new adventures in that galaxy far, far away... | Read more »
Swing Copters Review
Swing Copters Review By Jordan Minor on August 22nd, 2014 Our Rating: :: DIE TRYINGUniversal App - Designed for iPhone and iPad The creator of Flappy Bird is back with a vengeance.   | Read more »
Beam Me an Update Scotty – Star Trek Tre...
Beam Me an Update Scotty – Star Trek Trexels Receives its Biggest Update Yet Posted by Jessica Fisher on August 22nd, 2014 [ permalink ] | Read more »
The Outcast Review
The Outcast Review By Nadia Oxford on August 22nd, 2014 Our Rating: :: HANDS OFF. WAY OFF.Universal App - Designed for iPhone and iPad It’s easy to see what The Outcast is trying for, but its execution needs a lot of work.   | Read more »
HeroCraft Unveils New iOS Game, Marble D...
HeroCraft Unveils New iOS Game, Marble Duel Posted by Jessica Fisher on August 22nd, 2014 [ permalink ] HeroCraft is developing a new chain popper game called Marble Duel, wh | Read more »
Brain+ Review
Brain+ Review By Nadia Oxford on August 22nd, 2014 Our Rating: :: DIM BULBUniversal App - Designed for iPhone and iPad Brain+ is just another entry in an over-saturated brain-training marketplace – and not a particularly fun entry... | Read more »
The Witcher Battle Arena – New Gameplay...
The Witcher Battle Arena – New Gameplay Trailer Revealed Posted by Jessica Fisher on August 22nd, 2014 [ permalink ] Based in the Witcher universe, | Read more »
Max Gentlemen Review
Max Gentlemen Review By Jennifer Allen on August 22nd, 2014 Our Rating: :: OUTSTAYING ITS WELCOMEiPhone App - Designed for the iPhone, compatible with the iPad Max Gentlemen seems pretty quirky initially but that appeal wears thin... | Read more »

Price Scanner via MacPrices.net

Leftover 15-inch 2.0GHz Retina MacBook Pros a...
B&H Photo has leftover previous-generation 15″ 2.0GHz Retina MacBook Pros now available for $1599 including free shipping plus NY sales tax only. Their price is $400 off original MSRP. B&H... Read more
Pro.Calendar – New Productivity App for iPad...
Austin, Texas based mobile business and productivity app developer LightArrow, Inc. has announced Pro.Calendar, a powerful and intuitive calendar app with eight versatile calendar options including... Read more
SanDisk Ultra II SSD — Supercharge Your Syste...
SanDisk Corporation has announced the new SanDisk Ultra II SSD with enhanced SSD Dashboard. The new drive is designed to deliver a cost-effective and easy upgrade solution for PC owners looking to... Read more
Samsung and Barnes & Noble Introduce New...
Samsung Electronics America and NOOK Media, a subsidiary of Barnes & Noble, Inc. have announced the introduction of the new Samsung Galaxy Tab 4 NOOK, a 7-inch tablet combining Samsung’s leading... Read more
21-inch iMacs on sale for up to $150 off MSRP
B&H Photo has 21″ iMacs on sale for up to $150 off MSRP including free shipping plus NY sales tax only. B&H will also include a free copy of Parallels Desktop software: - 21″ 2.7GHz iMac: $... Read more
27-inch 3.2GHz iMac on sale for $1698, save $...
Abt has the 27″ 3.2GHz iMac on sale for $1698 including free shipping. Their price is $101 off MSRP. Read more
Mac Backup Guru 2.0 Drive Backup/Cloneing Uti...
Mac Backup Guru developer MacDaddy has released Mac Backup Guru 2.0, offering new and enhanced advanced features, such as bootable backups, synchronised volumes and folders, and a Snapshot mode that... Read more
Operate GE’s New Free-Standing KItchen Range...
Think you accidentally left the oven on? Switch it off while on the go. The new free-standing Profile™ Series gas and electric ranges are GE’s second cooking appliances, following their wall oven, to... Read more
Parallels Announces Parallels Desktop 10 for...
The no. 1-selling software for running Windows applications on a Mac becomes an even easier choice for millions of consumers and IT professionals worldwide with the launch of the most powerful... Read more
Apple now offering certified refurbished 2014...
 The Apple Store is now offering Apple Certified Refurbished 2014 MacBook Airs for up to $180 off the cost of new models. An Apple one-year warranty is included with each MacBook, and shipping is... Read more

Jobs Board

Position Opening at *Apple* - Apple (United...
**Job Summary** At the Apple Store, you connect business professionals and entrepreneurs with the tools they need in order to put Apple solutions to work in their Read more
Project Manager / Business Analyst, WW *Appl...
…a senior project manager / business analyst to work within our Worldwide Apple Fulfillment Operations and the Business Process Re-engineering team. This role will work Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** As more and more people discover Apple , they visit our stores seeking ways to incorporate our products into their lives. It's your job, as a Store Read more
Position Opening at *Apple* - Apple (United...
…Summary** As a Specialist, you help create the energy and excitement around Apple products, providing the right solutions and getting products into customers' hands. You Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.