[futurebasic] Re: [FB] Folder Confusion

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : September 2007 : Group Archive : Group : All Groups

From: Rich Love <richlove@...>
Date: Tue, 11 Sep 2007 10:33:46 -0500
David,

FOLDER ("Calendar Templates",0)  seems to be broken.
Here is a routine that will work for you. It uses a combination of FB  
and Applescript

Rich

Dim gAEResponse As Str255
include "AppleScript.INCL"

local fn FileExists(FilePathName$)
Dim AS OSErr             err
dim Path$
dim Exists%
Exists%=0


Route _toBuffer
Print "tell application ""Finder""
Print "visible of (info for alias " + chr$(34) + FilePathName$ + chr 
$(34) + ")"
Print "end tell"
err = Fn SendAppleScript
if gAEResponse = "true" then Exists% = 1
'otherwise it will say file not found
'gAEResponse = ""
end fn = Exists%

clear local mode
dim pBlock.128
dim dirName  as str255
dim pathName as str255
dim osErr    as OSErr
local fn getTheDirectoryPath$( theFSSpec as ^FSSpec )
pathName = theFSSpec.name
pBlock.ioNamePtr&    = @dirName ' put pointer to dirName$
pBlock.ioVRefNum%    = theFSSpec.vRefNum ' set vRefNum
pBlock.ioDirID&      = theFSSpec.parID ' set current directory ID
pBlock.ioFDirIndex%  = -1 ' get info on folder
do
long if fn PBGetCatInfoSync(@pBlock) == _noErr
long if pathName[0] + dirName[0] > 253
stop "Path exceeds 255 characters"
pathName =""
exit do
end if
pathName =  dirName + ":" + pathName ' add dirName to path
pBlock.ioDrDirID& = pBlock.ioDrParID& ' get folder's parent ID
xelse
'stop "Error tracing directory path"
pathName =""
exit do
end if
until pBlock.ioDirID& == _fsRtParID ' volume root ID
end fn = pathName


local fn WDRefNumToFSSpec( inName as str63, inWDRefNum as short,  
outFSSpec as ^FSSpec )
/*
Convert inName and wdRefNum to a FSSpec.
If inName is the null-string, the FSSpec is for a folder.
In Carbon, inWDRefNum is an FB-simulated wdRefNum.
*/
dim err as OSErr
if ( outFSSpec == 0) then err = _paramErr : exit fn
#if CarbonLib // simulated wdRefNum
inWDRefNum -= _FBWDStartNum
long if ( inWDRefNum >= 0 ) and ( inWDRefNum < _FBWDListSize )
outFSSpec.vRefNum = gFMWDVolList%(inWDRefNum)
outFSSpec.parID   = gFMWDDirList&(inWDRefNum)
outFSSpec.name    = inName
err = _noErr
xelse
err = _fnfErr
end if
#else // "real" wdRefNum
err = fn FSMakeFSSpec( inWDRefNum, 0, inName, #outFSSpec )
#endif
end fn = err

LOCAL FN getDirectoryPath$ (ThewdRefNum)
'this gets the full path to the working directory
dim fSpec    as FSSpec
dim wdRefNum as short
dim err      as OSErr
dim DirPath$

wdRefNum = ThewdRefNum

'this just gets the volume name that MacWise is on with a colon after it
err = fn WDRefNumToFSSpec( "", wdRefNum, fSpec )


DirPath$ = fn getTheDirectoryPath$( fSpec ) // get the path

end fn = DirPath$

MyAppFolderPath$ =  FN getDirectoryPath$ (system(_aplvol))

long if fn FileExists(MyAppFolderPath$ + "Templates")
'this will set the current folder to Templates in your app folder  
only if templates already exists
'Rich Love 9/11/2007
gPrefFolderVol = FOLDER ("Templates",system(_aplvol))

Print "Templates folder found and it is now the current folder"
do
until fn button
end if



============================================================
On Sep 10, 2007, at 1:34 PM, David Bailey wrote:

> I have been using this small function
>
>
> CLEAR LOCAL
> DIM pbBlk.128,Filename$,Index%,OSErr%,menuid,loop
> dim mHndl as handle
> '~'2
> LOCAL FN BuildPrefMenu
> '~'2
> gPrefFolderVol = FOLDER ("Templates",system(_aplvol))
> Index% = 1
> menuid = 1
> gNumPrefFiles = 0
> deletemenu(_templatesMenu)
> DO
> pbBlk.ioFDirIndex%  = Index%
> pbBlk.ioNamePtr&    = @Filename$
> pbBlk.ioVRefNum%    = gPrefFolderVol
> pbBlk.ioDirID&      = 0
> FN FBWDtoPBWD(pbBlk)
> OSErr% = FN PBHGetFInfoSync (pbBlk)
> gFileType&          = pbBlk.ioBuffer&
> LONG IF OSErr% = _noErr
> LONG IF gFileType& = _"Pref"
> long IF menuid = 1
> MENU _TemplatesMenu,0,_enable,"Templates"
> end if
> MENU _TemplatesMenu,menuid,_enable,Filename$
> INC(menuid)
> END IF
> END IF
> INC (Index%)
> UNTIL OSErr% <> _noErr
> gNumPrefFiles = menuid
> END FN
>
>
> To build a templates menu and it works fine.  I just discovered  
> however that using (FOLDER ("Templates",system(_aplvol)) instead of  
> FOLDER ("Calendar Templates",0)
> creates the folder if it is not there.  Switching to the second  
> version the function does not work.  Am I using the Folder  
> statement correctly?  I never want to create a folder
> I want to count, get names, open resource files within, etc.
>
> Also it seems that using Folder to set the default directory does  
> not mean a File$ command will open the dialog in that folder.   
> Discussed several times in the archives.  Has anyone
> figured out how to do that within FB?
>
> David
>
> --
> To unsubscribe, send ANY message to: futurebasic- 
> unsubscribe@...
>