home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / BASIC / POWBASIC / LIBRARY1 / EXISTS.ZIP / EXISTS.BAS < prev    next >
BASIC Source File  |  1990-02-14  |  5KB  |  138 lines

  1.  $COMPILE UNIT  'make a unit
  2.  ' TB - bug fixes 7/4/88 originally made 3-27-88
  3.  ' PB Version 1/25/90 2/14/90
  4.  ' To compile in the IDE, simply Alt-F9
  5.  ' to compile from the command line,
  6.  ' PBC EXISTS -CU
  7.  ' note: to use the debugger, you must compile from the IDE
  8.  ' as no debugging action is passed from the PBC.
  9.  
  10.  %False = 0
  11.  %True = NOT %False
  12.  
  13.  EXTERNAL MatchedFil$'make it global
  14.  
  15.  ' the following sub, made PUBLIC, allows the main to access it
  16.  
  17. SUB FindVol(Filename$,FileErr%,CreateDate$,CreatTime$) PUBLIC
  18.  MatchedFil$ = ""
  19.  'set up DTA     'Barry Erick 75300,214   , B.ERICK
  20.  
  21.  REG 1, &H2F00         'get DOS's dta
  22.  CALL INTERRUPT &H21   ' to find returned file info
  23.  DTASegment& = REG(9)  'es
  24.  DTAOffset&  = REG(2)  'bx
  25.  FExist$  = Filename$+CHR$(0)     ' make it a ASCIIZ string for DOS
  26.  
  27.  ' Note the StrPtr and StrSeg. This is the major change
  28.  ' from a TB program. In TB, we would :
  29.  ' Def Seg
  30.  ' StrSeg&  = PEEK(1)*256+PEEK(0)   ' Find TB's String Segment
  31.  ' DEF SEG  = VARSEG(FExist$)       ' Look for pointer
  32.  ' StringSegPtr&    = VARPTR(FExist$)' Point to TB's string Segment
  33.  ' StringSegOffset& = PEEK(StringSegPtr&+2)+256 * PEEK(StringSegPtr&+3)
  34.  ' DEF SEG              ' Restore Default Segment
  35.  ' REG 8,StrSeg&        ' String Segment  to Reg DS
  36.  ' REG 4,StringSegOffset&' String Seg Offset to Reg DX
  37.  ' REG 3,&H7            ' Find all matching files Attribute
  38.  ' REG 1,&H4E00         ' DOS Function Find First Match
  39.  ' CALL INTERRUPT &H21  ' Just look for first matching file
  40.  ' FileErr% = REG(1)     ' Reg AX.. 0 = no error
  41.  ' DEF SEG  = DTASegment&
  42.  
  43.  ' But because of PB's unlimited string space, we do it this way:
  44.  
  45.  REG 8,StrSeg(FEXIST$)' String Segment  to Reg DS
  46.  REG 4,StrPTR(FEXIST$)' String Seg Offset to Reg DX
  47.  ' The rest is the same as a TB program, but MUCH faster
  48.  REG 3,&H23            ' Find all matching files 'cept vol or dir
  49.  REG 1,&H4E00         ' DOS Function Find First Match
  50.  CALL INTERRUPT &H21  ' Just look for first matching file
  51.  FileErr% = REG(1)     ' Reg AX.. 0 = no error
  52.  DEF SEG  = DTASegment& 'point to the DTA
  53.  ' Get the creation date that dos just stuck in the dta
  54.  FOR X = 1 TO 11
  55.      IF PEEK(DTAOffset&+x)=0 THEN EXIT FOR'none found
  56.      MatchedFil$=Matchedfil$+CHR$(PEEK(dtaOffset& + x))
  57.  NEXT
  58.  IF LEFT$(MatchedFil$,1) <> CHR$(&H13) THEN
  59.     MatchedFil$=LEFT$(MatchedFil$,8)+"."+RIGHT$(MatchedFil$,3)
  60.  END IF
  61.  d1! = PEEK(23+DTAOffset&)
  62.  d2! = PEEK(22+DTAOffset&)
  63.  CreateDate& = PEEK(25+DTAOffset&)*256+PEEK(24+DTAOffset&)
  64.  creattime& = d1*256
  65.  INCR creattime&,d2
  66.  
  67.  ' now start tearing apart the words returned
  68.  hour%       = INT(CreatTime&/2048)
  69.  hours%      = hour%
  70.  IF hour% >12 THEN    'returned in 24 hour time, make 12 hour time
  71.     DECR hours%,12
  72.     pm% = %true
  73.  ELSE
  74.     pm% = %False
  75.  END IF
  76.  hour$ = MID$(STR$(hours%),2)'strip leading space
  77.  minutes% = (CreatTime&-(CLNG(hour%)*2048))\32
  78.  minutes$ = MID$(STR$(minutes%),2)' strip leading space
  79.  IF LEN(minutes$)=1 THEN minutes$="0"+minutes$
  80.  
  81.  Year%       = CreateDate&\512
  82.  Year$       = MID$(STR$(Year%+1980),2)' minimum dos date is 1/1/1980
  83.  Month%      = (CreateDate&-(Year%*512))\32
  84.  Month$      = MID$(STR$(Month%),2)
  85.  Day$        = MID$(STR$(CreateDate& MOD 32),2)
  86.  IF LEN(day$)= 1 THEN day$= "0"+day$
  87.  IF FileErr% = 0 THEN
  88.     CreateDate$   = Month$+"-"+Day$+"-"+Year$
  89.     CreatTime$    = Hour$+":"+MINUTES$
  90.     IF pm% THEN
  91.        CreatTime$ = CreatTime$+" pm"
  92.     ELSE
  93.        CreatTime$ = CreatTime$+" am"
  94.     END IF
  95.  ELSE
  96.     CreatTime$  = ""
  97.     CreateDate$ = ""
  98.  END IF
  99.  DEF SEG
  100. END SUB
  101.  
  102.  ' The next item is made available to outside the UNIT
  103.  
  104.  FUNCTION FileExist%(Filename$) PUBLIC
  105.  CALL FINDVOL(FileName$,Ferr%,a$,b$)
  106.  SELECT CASE Ferr%
  107.         CASE 0
  108.              FileExist% = %True
  109.         CASE ELSE
  110.              FILEEXIST% = 0
  111.  END SELECT
  112.  END FUNCTION
  113.  
  114.  ' The following is a demo
  115.  ' The Sub does not require a DEFINT A-Z, as all variables are labeled.
  116.  
  117.  
  118.  ' CLS
  119.  ' LINE INPUT "Which filename do you need to check ";filename$
  120.  ' CALL FindVol(Filename$,FileErr%,CreateDate$,CreatTime$)
  121.  ' SELECT CASE FileErr%
  122.  '    CASE 0
  123.  '         PRINT "I found ";UCASE$(filename$)
  124.  '         PRINT "Created ";CreateDate$;
  125.  '         PRINT " at ";CreatTime$
  126.  '    CASE 2,18
  127.  '         PRINT "No File Found."
  128.  ' END SELECT
  129.  ' END (FileErr%)
  130.  
  131.  ' IF FileExist%(filename$)  then
  132.     '  print "I found ";filename$
  133.     ' END(0)
  134.     '  else
  135.     '  print "NotFound
  136.     ' END(53)
  137.     '  end if
  138.