how to open all files in a folder

how to open all files in a folder

Post by David Phil » Wed, 02 Jul 2003 15:01:57


In article < XXXX@XXXXX.COM >,



Mean what you say: if you want the user to select a folder to open in
its entirety, you should be using NavChooseFolder.

Once you have an FSSpec for a folder, you can use something like
PBGetCatInfoSync to iterate over all the files in the folder.

Read Files.h for more directory iterators.
 
 
 

how to open all files in a folder

Post by David Phil » Thu, 03 Jul 2003 11:27:05

In article < XXXX@XXXXX.COM >,



Call my Open1() on it, below. Note: you can't modify a folder while you are
iterating over it. Create your dest files somewhere else.

/* OpenFile - the meat of this program.

*/
static OSErr OpenFile(FSSpecPtr fsp, OSType creator, OSType type){
OSErr errCode = noErr;
/// ... your code here.
return errCode;
}

/* OpenFolder - iterate over each item in the folder, applying FolderOrFile as appropriate
we pass in a pointer to a CInfoPBRec and a FileSpec to re-use, to save stack space.
*/
static OSErr OpenFolder(CInfoPBPtr iop, long dirID, FSSpecPtr fsp){
long i;
OSErr errCode;

errCode = noErr;
fsp->parID = dirID;
for(i = 1; noErr == errCode && ! gDone; i++){
iop->hFileInfo.ioNamePtr = fsp->name;
iop->hFileInfo.ioVRefNum = fsp->vRefNum;
iop->hFileInfo.ioFDirIndex = i;
iop->hFileInfo.ioDirID = dirID;
if(noErr != PBGetCatInfoSync(iop)){
break; // <-- loop exit
}
// skip aliases and invisibles.
if((kIsAlias|kIsInvisible) & iop->hFileInfo.ioFlFndrInfo.fdFlags){
/* empty */
}else if(ioDirMask & iop->hFileInfo.ioFlAttrib){
errCode = OpenFolder(iop, iop->dirInfo.ioDrDirID, fsp);
}else{
fsp->parID = dirID;
errCode = OpenFile(fsp, iop->hFileInfo.ioFlFndrInfo.fdCreator, iop->hFileInfo.ioFlFndrInfo.fdType);
}
}
return errCode;
}


/* OpenFolderOrFile - pass in CInfoPBPtr to conserve stack space
*/
static OSErr OpenFolderOrFile(CInfoPBPtr iop, FSSpecPtr fsp){
OSErr errCode = noErr;
iop->hFileInfo.ioNamePtr = fsp->name;
iop->hFileInfo.ioVRefNum = fsp->vRefNum;
iop->hFileInfo.ioFDirIndex = 0;
iop->hFileInfo.ioDirID = fsp->parID;
errCode = PBGetCatInfoSync(iop);
if(noErr == errCode){
// skip aliases and invisibles.
if((kIsAlias|kIsInvisible) & iop->hFileInfo.ioFlFndrInfo.fdFlags){
/* empty */
}else if(ioDirMask & iop->hFileInfo.ioFlAttrib){
errCode = OpenFolder(iop, iop->dirInfo.ioDrDirID, fsp);
}else{
errCode = OpenFile(fsp, iop->hFileInfo.ioFlFndrInfo.fdCreator, iop->hFileInfo.ioFlFndrInfo.fdType);
}
}
return errCode;
}



/* Open1 - the meat of this program.
GetCatInfo on it. if a file, dispatch. if a folder dispatch.
Since OpenFolderOrFile is recusive, we allocate a single CInfoPBRec here to minimize
stack space used.
*/
static OSErr Open1(FSSpecPtr fsp){
CInfoPBRec io;

return OpenFolderOrFile(&io, fsp);
}