TweetFollow Us on Twitter

Jan 96 Tips
Volume Number:12
Issue Number:1
Column Tag:Tips & Tidbits

Tips & Tidbits

By Steve Sisak, Contributing Editor

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

Here is a handy function for making sure that an undeletable “file from hell” doesn’t get in the way during program execution, just move it to the Trash. This only works when the file is on the same volume as the Trash, however.

Greg Poole

File: FSpTrashFile.h

/******************************************************************************
    FSpTrashFile.h
    
    history:
    modified:  xx/xx/xx  who are you? what did you do?
    created:   11/23/94         greg poole

    Greg Poole
    Vital Images, Inc.
    email: greg@vitalimages.com

 ******************************************************************************/

#pragma once

#ifdef __cplusplus
 extern "C" {
#endif
 extern OSErr  FSpTrashFile( FSSpecPtr file );
#ifdef __cplusplus
 }
#endif


File: FSpTrashFile.c
    
/******************************************************************************
    Move a file to the trash if it is not possible to delete it.
    Can only move file to the trash if it is on the same volume
    as the file to be deleted.
 ******************************************************************************/

#include <Folders.h>
#include "FSpTrashFile.h"

OSErr FSpTrashFile( FSSpecPtr theFile )
{
 OSErr  theErr = noErr;
 short  vRefNum;
 long   dirID;
 FSSpec spec;
 FSSpecPtrtheTrash = &spec;
 
    // don’t go any further if there isn’t a file to deal with or if the
    // file was deleted successfully
    //
 theErr = FSpDelete( theFile );
 if ( theErr == fnfErr || theErr == noErr )
 return noErr;
 
    // if we got this far, we had a problem deleting the file,
    // don’t worry, relax and just trash it
 theErr = FindFolder( kOnSystemDisk, kTrashFolderType, 
 kDontCreateFolder, &vRefNum, &dirID );
 
 if ( theErr == noErr )
 theErr = FSMakeFSSpec( vRefNum, dirID, "\p", theTrash );

 if ( theErr == noErr )
 if ( theFile->vRefNum != theTrash->vRefNum )
 theErr = diffVolErr;
 
 if ( theErr == noErr )
 theErr = CatMove( theFile->vRefNum, theFile->parID, 
 theFile->name, theTrash->parID, theTrash->name );

 return theErr;
 
} // end FSpTrashFile

// define TEST_TRASH_FILE for a standalone test
#define TEST_TRASH_FILE

#if defined( TEST_TRASH_FILE )

    // local function prototypes
 static void     InitTheMac( void );
 static Boolean  GetAFile( FSSpecPtr file );
 
 static void InitTheMac( void )
 {
 InitGraf( &qd.thePort );
 InitFonts();
 InitWindows();
 InitMenus();
 TEInit();
 InitDialogs( 0L );
 InitCursor();
 MaxApplZone();
 } // end InitTheMac
 
 static Boolean GetAFile( FSSpecPtr file )
 {
 SFTypeList types;
 StandardFileReply reply;
 
 StandardGetFile( NULL, -1, types, &reply );
 if ( reply.sfGood )
 BlockMove( &reply.sfFile, file, sizeof( FSSpec ) );
 return reply.sfGood;
 } // end GetAFile

 void main( void )
 {
 FSSpec srcFileSpec;
 OSErr  theErr = noErr;
 
 InitTheMac();
 if ( GetAFile( &srcFileSpec ) )
 theErr = FSpTrashFile( &srcFileSpec );
 } // end main

#endif // TEST_TRASH_FILE

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Black Hole Joyrider (Games)
Black Hole Joyrider 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: Guide your spacecraft through the gravity well of a powerful black hole using only your retro-thrusters and dwindling fuel... | Read more »
My Koi (Games)
My Koi 1.0 Device: iOS iPhone Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: My Koi is a beautiful and relaxing fish pond app. Customise and name each fish. Feed them daily. Watch them grow. Collect new fish.... | Read more »
Never Gone (Games)
Never Gone 1.0.2 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0.2 (iTunes) Description: ###IMPPORTANT### Never Gone's HD art resources require devices with more than 1GB RAM, so please note that iPhone 4/4s, iPad 2/... | Read more »
INKS. (Games)
INKS. 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: From the makers of BAFTA-winning Lumino City comes INKS. INKS updates pinball for a new generation. It combines the joy of pinball with... | Read more »
How to maximise your profits in Bakery B...
Running a bakery can be an expensive venture. You’ll need to continuously upgrade your oven, your kitchen supplies, and even your ingredients to keep customers happy. Most of these renovations in Bakery Blitz cost a pretty penny, but we have a few... | Read more »
How to manage your time in Bakery Blitz
It can be tricky, especially when you risk burning your kitchen to the ground if you forget a cake in the oven, so make sure to use these time management tricks to keep your bakery running smoothly. Don’t collect the money right away [Read more] | Read more »
Model 15 (Music)
Model 15 1.0 Device: iOS iPhone Category: Music Price: $29.99, Version: 1.0 (iTunes) Description: The Moog Model 15 App is the first Moog modular synthesizer and synthesis educational tool created exclusively for iPad, iPhone and... | Read more »
How to deal with wind in Angry Birds Act...
Angry Birds Action! is a physics-based puzzler in which you're tasked with dragging and launching birds around an obstacle-littered field to achieve a set objective. It's simple enough at first, but when wind gets introduced things can get pretty... | Read more »
How to get three stars in every level of...
Angry Birds Action! is, essentially, a pinball-style take on the pull-and-fling action of the original games. When you first boot it up, you'll likely be wondering exactly what it is you have to do to get a good score. Well, never fear as 148Apps... | Read more »
The beginner's guide to Warbits
Warbits is a turn-based strategy that's clearly inspired by Nintendo's Advance Wars series. Since turn-based strategy games can be kind of tricky to dive into, see below for a few tips to help you in the beginning. Positioning is crucial [Read... | Read more »

Price Scanner via MacPrices.net

12-inch 128GB iPad Pros on sale for up to $10...
B&H Photo has 12″ 128GB WiFi iPad Pros on sale for up to $100 off MSRP, each including free shipping. B&H charges sales tax in NY only: - 12″ Space Gray 128GB WiFi iPad Pro: $899 $50 off MSRP... Read more
Global Tablet Sales Slump Continues, iPad’s F...
Another miserable showing for the global slate tablet category in calendar Q1/16, with global tablet shipments falling another 1ten percent to 46.5 million units during the according to Strategy... Read more
Revel Systems to Showcase iPad POS Platform w...
Revel Systems, specialists in iPad Point of Sale management solution for brick-and-mortar retail, food businesses and more, today announced that it will showcase its innovative iPad Point of Sale... Read more
13-inch 2.5GHz MacBook Pro on sale for $999,...
B&H Photo has the 13″ 2.5GHz MacBook Pro on sale for $999 including free shipping plus NY sales tax only. Their price is $100 off MSRP. Read more
Apple refurbished 2015 iMacs available for up...
Apple now has a full line of Certified Refurbished 2015 21″ & 27″ iMacs available for up to $350 off MSRP. Apple’s one-year warranty is standard, and shipping is free. The following models are... Read more
Indian Smartphone Market Grows Annually by 12...
India’s smartphone market grew by 12 percent year-over-year, with 24.4 million units shipping in Q1 2016. The top five vendors stayed the same, with Samsung in the lead, followed by Micromax, Intex... Read more
Get Notifications When Your Friend’s Phone Ba...
Calgary, Canada based Stonelight Pictures has announced the release of Battery Share 1.0.1, its new utility for iOS 9 supported devices. The company notes that people are spending more time on their... Read more
11-inch 1.6GHz/128GB MacBook Air on sale for...
Amazon has the current-generation 11″ 1.6GHz/128GB MacBook Air (sku MJVM2LL/A) on sale for $749.99 for a limited time. Their price is $150 off MSRP, and it’s the lowest price available for this model... Read more
Price drops on clearance 2015 13-inch MacBook...
B&H Photo has dropped prices on clearance 2015 13″ MacBook Airs by up to $250. Shipping is free, and B&H charges NY sales tax only: - 13″ 1.6GHz/4GB/128GB MacBook Air (MJVE2LL/A): $799, $200... Read more
Mac minis on sale for up to $100 off MSRP
B&H Photo has Mac minis on sale for up to $100 off MSRP including free shipping plus NY sales tax only: - 1.4GHz Mac mini: $449 $50 off MSRP - 2.6GHz Mac mini: $649 $50 off MSRP - 2.8GHz Mac mini... Read more

Jobs Board

*Apple* Retail - Multiple Positions (US) - A...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
Restaurant Manager (Neighborhood Captain) - A...
…in every aspect of daily operation. WHY YOU'LL LIKE IT: You'll be the Big Apple . You'll solve problems. You'll get to show your ability to handle the stress and Read more
Automotive Sales Consultant - Apple Ford Linc...
…you. The best candidates are smart, technologically savvy and are customer focused. Apple Ford Lincoln Apple Valley is different, because: $30,000 annual salary Read more
Restaurant Manager (Neighborhood Captain) - A...
…in every aspect of daily operation. WHY YOU'LL LIKE IT: You'll be the Big Apple . You'll solve problems. You'll get to show your ability to handle the stress and Read more
Simply Mac *Apple* Specialist- Service Repa...
Simply Mac is the largest premier retailer of Apple products in the nation. In order to support our growing customer base, we are currently looking for a driven Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.