home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / disks / disk463.lzh / FileIO / BASIC / MultipleFileIO (.txt) next >
AmigaBASIC Source Code  |  1991-03-09  |  5KB  |  163 lines

  1.  CLS
  2.  LOCATE 1,8
  3.  PRINT "Demo AmigaBasic program using the FileIO MULTIPLE_SELECT files"
  4.  LOCATE 2,11
  5.  PRINT "Atrociously hacked together by Jeff Glatt (dissidents)"
  6.  
  7.  DEFLNG a-Z
  8.  
  9.  LIBRARY "requester.library"
  10.  LIBRARY "exec.library"
  11.  
  12.  DECLARE FUNCTION AllocMem() LIBRARY
  13.  
  14.  DECLARE FUNCTION DoFileIOWindow() LIBRARY  
  15.  DECLARE FUNCTION GetFileIO() LIBRARY 
  16.  DECLARE FUNCTION AutoFileMessage() LIBRARY
  17.  DECLARE FUNCTION AutoPrompt3() LIBRARY
  18.  DECLARE FUNCTION RetrieveEntry() LIBRARY
  19.  
  20.  MEMF.PUBLIC = 1 : MEMF.CLEAR = 65536 : BUFSIZE = 202
  21.  BufferPtr=AllocMem(BUFSIZE,MEMF.PUBLIC+MEMF.CLEAR) 'A buffer to copy the pathname to
  22.  IF BufferPtr = 0 THEN GOTO NoMem1 
  23.  
  24.  BUFSIZE2 = 24
  25.  ExtPtr=AllocMem(BUFSIZE2,MEMF.PUBLIC+MEMF.CLEAR)
  26.  IF ExtPtr = 0 THEN GOTO NoMem2 
  27.  
  28.  FileIO=GetFileIO(0) 
  29.  IF FileIO = 0 THEN GOTO CloseUp1
  30.  
  31.  POKEL FileIO+248,BufferPtr
  32.  
  33.  POKEL FileIO+222,ExtPtr
  34.  
  35.  message$ = ""
  36.  WindowTitle$ = "Multiple Select Files" + message$
  37.  POKEL FileIO+244,SADD(WindowTitle$)
  38.  POKE  FileIO+261,1  'JAM2 DrawMode
  39.  POKE  FileIO+262,1  'PenA = Color1
  40.  POKE  FileIO+263,0  'PenB = Color0
  41.  DIM   Pathname$(202)
  42.  DIM   Filename$(30)
  43.  DIM   VolName$(30)
  44.  DIM   DrawerName$(132)
  45.   
  46. Again:
  47.   'suppress the .info files and do MULTIPLE_FILES
  48.   POKE  FileIO+1,128+64
  49.   
  50. DoIO:
  51.  Result=DoFileIOWindow(FileIO,0)  'do the FileIO selection on WB screen  
  52.  
  53.  IF Result <> -1 THEN GOTO CheckError    '-1 means the user selected CANCEL.
  54.  message$ = "User selected CANCEL."+CHR$(0)
  55.  CALL AutoMessageLen(SADD(message$),WINDOW(7),21) '21 is the number of chars in Message$ not counting the CHR$(0)
  56.  GOTO CloseUp2
  57.  
  58. CheckError:
  59.  '0 means the FileIO window couldn't open (probably due to lack of mem).
  60.  'Too bad! You'll have to get the filename some other way. Maybe an INPUT statement?
  61.  IF Result <> 0 THEN GOTO GotPathname              
  62.  'Message number 0 in the FileIO lib says "Out of memory for this operation" 
  63.  Result=AutoFileMessage(0,WINDOW(7))
  64.  GOTO Retry
  65.  
  66. GotPathname:       'We got a selection from the user!
  67.  'Now, our PathBuffer$ has the complete pathname. The FileIO's Filename
  68.  'buffer has just the Filename separated from the disk and drawer names
  69.  '(which are also separated into their own FileIO buffers). Let's copy out
  70.  'the disk and drawers to a dir string, then we'll use RetrieveEntry() to
  71.  'get each selected file within that dir. Note that the user could have typed
  72.  'in a filename not in the list. If this is important, examine the FileIO's
  73.  'FileSize field. If not 0, then the user selected one of the ones in the list.
  74.  'If 0, then the user typed in a new filename (not in the list) and the
  75.  'returned PathBuffer$ is the full name, and the filename part is in the
  76.  'FileIO's Filename buffer. Here, I ignore any new filename
  77.  
  78.  'Copy out all the drawers 
  79.  DrawerName$ = ""
  80.  FOR i = 0 TO 132
  81.     value = PEEK(FileIO+32+i)
  82.     IF value = 0 THEN GOTO CopyVol
  83.     char$ = CHR$(value)
  84.     DrawerName$ = DrawerName$+char$    
  85.  NEXT i
  86.  
  87. CopyVol: 'Copy out the diskname 
  88.  VolName$ = ""
  89.  FOR i = 0 TO 30
  90.     value = PEEK(FileIO+164+i)
  91.     IF value = 0 THEN GOTO CopyFN
  92.     char$ = CHR$(value)
  93.     VolName$ = VolName$+char$    
  94.  NEXT i
  95.  
  96. CopyFN:
  97.   fileEntryPtr = 0 'initially 0
  98.  
  99. NextSelect:
  100.   Pathname$ = DrawerName$ + VolName$
  101.   'Get the next FileEntry
  102.   entry = RetrieveEntry(VARPTR(fileEntryPtr),FileIO)
  103.   'Was there another selection?
  104.   IF entry = 0 THEN GOTO Retry
  105.   'Get the Entry structure from the FileEntry
  106.   ptr = PEEKL(entry+8)
  107.  
  108.   Filename$ = ""
  109.  'Copy out the Filename to Filename$.
  110.  FOR i = 0 TO 30
  111.     value = PEEK(ptr+5+i)
  112.     IF value = 0 THEN GOTO PrintPath
  113.     char$ = CHR$(value)
  114.     Filename$ = Filename$+char$    
  115.  NEXT i
  116.  
  117. PrintPath:
  118.   'Now append the filename to the dir
  119.   Pathname$ = Pathname$ + Filename$
  120.  
  121.  CALL AutoMessage(SADD(Pathname$),WINDOW(7)) 'display our complete path in a
  122.                                              'requester first
  123.  
  124.  CLS
  125.  LOCATE 7,1
  126.  PRINT
  127.  'Let's print out the disk, drawers, and filename
  128.  PRINT "The Diskname is ",VolName$
  129.  PRINT "The Drawernames are ",DrawerName$
  130.  PRINT "The Filename is ",Filename$ 'Note that there is no Filename if the
  131.                                     'user selected only a disc or drawer.
  132.   
  133.  'Let's get the amount of free disk space on the disk that the user chose
  134.  PRINT "Free disk space: ",PEEKL(FileIO+236)," bytes."
  135.  
  136.  'Note: we get the size from the Entry
  137.  PRINT "Size of file:    ",PEEKL(ptr)," bytes."
  138.   
  139.  'Go back for next selection if there is one
  140.  GOTO NextSelect
  141.   
  142. Retry:
  143.  message$  = "This has been a test of the FileIO library." + CHR$(0)
  144.  Message2$ = "Do you want to retry?" + CHR$(0)
  145.  boolean=AutoPrompt3(SADD(message$),SADD(Message2$),0,WINDOW(7))
  146.  CLS
  147.  IF boolean = 1 THEN GOTO Again
  148.  
  149. CloseUp2: 
  150.  CALL ReleaseFileIO(FileIO)        'Free the FileIO structure
  151.   
  152. CloseUp1:
  153.  CALL  FreeMem(ExtPtr,BUFSIZE2)
  154.  
  155. NoMem2:
  156.  CALL  FreeMem(BufferPtr,BUFSIZE)
  157.  
  158. NoMem1: 
  159.  LIBRARY CLOSE
  160.  END
  161.  
  162.  
  163.