[futurebasic] Re: [FB] Command line from FB to archive a file

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : November 2006 : Group Archive : Group : All Groups

From: Brian Stevens <bstevens33@...>
Date: Fri, 17 Nov 2006 13:39:24 -0700
N.B.  This is a VERY quick hack but changing FN ZipUnzip something  
like this:

local mode
local fn ZipUnzip( zip as Boolean )
'~'1
dim as Str255 command, response, path
dim as FSSpec spec

long if ( files$( _FSSpecOpen,,, spec ) )
if ( zip ) then command = "gzip -c -N " else command = "gunzip "
path =  fn PathForOpenUNIX$( spec )
command += path + " > "
mid$(path,len(path)-3,4) = ".zip"
command += path
open "UNIX" , 1, command
line input #1, response
close 1
end if
end fn

will  force a new file and preserve the original. Again, the code is  
crude but the idea is there.

Brian S.





On Nov 17, 2006, at 10:05 AM, Bernie wrote:

>
> Steve wrote:
>
>> I want to have OS X create an archive file [.zip] and call it from  
>> FB.  I can do it with AppleScript, but it is too complicated and  
>> prone to errors.
>> Maybe Ken has done this with a Unix call ?
>> I want to compress a file, before FTP upload via curl.
>
>
> I pinched the bulk of this from a demo by Robert P. Select either  
> Zip or Unzip from the File menu. Unfortunately, the original file  
> is removed after the zip/unzip. Maybe Ken can show us how to keep  
> the original?
>
> Bernie
>
>
> '----------
> local mode
> local fn EscapeBadCharacters$( path as Str255 )// Robert P
> '~'1
> dim as Str255 badGuys, badGuy
> dim as long nBadGuys, badIndex
>
> badGuys = " ""'?()&;|$"
> badGuys += "\" /* must be last */
> nBadGuys = badGuys[0]
> while ( nBadGuys )
> badGuy = mid$( badGuys, nBadGuys, 1 )
> badIndex = instr( 1, path, badGuy )
> while ( badIndex )
> if ( path[0] == 255 ) then path[0] = 0 : exit fn // would overflow
> path = left$( path, badIndex - 1 ) + "\" + mid$( path,  
> badIndex ) // escape it
> badIndex = instr( badIndex + 2, path, badGuy ) // set to continue  
> search
> wend
> nBadGuys--
> wend
> end fn = path
>
>
> local mode
> local fn PathForOpenUNIX$( fs as ^FSSpec )// Robert P
> '~'1
> dim as FSRef myFSRef
> dim as Str255 path
>
> path[0] = 0
> long if ( _noErr == fn FSpMakeFSRef( #fs, @myFSRef ) )
> if ( fn FSRefMakePath( myFSRef, @path, 255 ) ) then path[0] = 0 //  
> null string if too long
> fn FBCStr2PStr( path ) // convert to Pascal string
> end if
> end fn = fn EscapeBadCharacters$( path ) // 0-terminated Pascal string
>
>
> local mode
> local fn ZipUnzip( zip as Boolean )
> '~'1
> dim as Str255 command, response
> dim as FSSpec spec
>
> long if ( files$( _FSSpecOpen,,, spec ) )
> if ( zip ) then command = "gzip " else command = "gunzip "
> command += fn PathForOpenUNIX$( spec )
> open "UNIX" , 1, command
> line input #1, response
> close 1
> end if
> end fn
>
>
> local mode
> local fn DoMenu
> '~'1
> select menu( _menuID )
> case 1
> select menu( _itemID )
> case 1 : fn ZipUnzip( _zTrue )
> case 2 : fn ZipUnzip( _false )
> end select
> end select
> menu
> end fn
>
> menu 1,0,1,"File"
> menu 1,1,1,"Zip…"
> menu 1,2,1,"Unzip…"
>
> on menu fn DoMenu
>
> do
> HandleEvents
> until gFBQuit
> '----------
>
> --
> To unsubscribe, send ANY message to: futurebasic- 
> unsubscribe@...
>