home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / compiler / sample10.bas < prev    next >
BASIC Source File  |  1992-05-08  |  4KB  |  191 lines

  1.  
  2.  
  3.  rem
  4.  rem Here is another program which is fairly standard in it's
  5.  rem use of the Basic language, but which uses some of the advanced
  6.  rem Directory commands of BasicBasic.
  7.  rem
  8.  
  9.   rem windows size 10,5,70,14
  10.  
  11.  REM THIS PROGRAM ALLOWS THE USER TO SEARCH A DISK LOOKING FOR
  12.  REM A GIVEN FILE NAME.  IT WILL SEARCH ALL FILES BELOW THE USER
  13.  REM ENTERED PATHNAME
  14.  
  15.  REM THIS PROGRAM CAN BE EASILY MODIFIED TO SEARCH ALL FILES FOR
  16.  REM A PARTICULAR SEQUENCE OF BYTES
  17.  
  18.  
  19.      COLOR 7,1
  20.      cls
  21.  
  22.  rem
  23.  rem Initialize some variables
  24.  rem
  25.      maxlevel=20
  26.      direc=0
  27.      dim direc(maxlevel)
  28.      dim direcname$(maxlevel)
  29.      dlevel=0
  30.      numfiles=0
  31.      numfound=0
  32.  
  33.  rem
  34.  rem get starting directory to search
  35.  rem and string to search for
  36.  rem
  37.  
  38.  getinput:
  39.  
  40.     LOCATE 5,34
  41.     COLOR 1,7
  42.     PRINT "FIND FILE";
  43.     COLOR 7,1
  44.     locate 8,15
  45.     print "Enter file name to search for:";
  46.     locate 7,15
  47.     input "Enter Starting Path: ";firstlevel$
  48.     if firstlevel$="" then stop
  49.     if len(firstlevel$)=1 then
  50.       firstlevel$=firstlevel$+":\"
  51.     end if
  52.     if right$(firstlevel$,1)<>"\" then
  53.         firstlevel$=firstlevel$+"\"
  54.     end if
  55.     locate 8,15
  56.     input "Enter file name to search for: ";st$
  57.     ST$=UCASE$(ST$)
  58.     sd$=firstlevel$
  59.  
  60.  rem
  61.  rem here is where we would check to make sure input strings are OK
  62.  rem
  63.  
  64.  
  65.  
  66. newdirectory:
  67.  
  68.  rem
  69.  rem Look for first file in new directory
  70.  rem 
  71.  
  72.   sd$=firstlevel$
  73.   for i=1 to dlevel
  74.      sd$=sd$+direcname$(i)+"\"
  75.   next i
  76.   ffname$ = DIR$(sd$+"*.*")
  77.  
  78.  rem
  79.  rem Now search each regular file in this directory (there may be none)
  80.  rem
  81.  
  82. nextfile:
  83.   IF ffname$ <> "" THEN
  84.    numfiles=numfiles+1
  85.    locate 10,15
  86.    print ffname$;"           ";
  87.    if ffname$=st$ then
  88.     numfound=numfound+1
  89.     locate 12,15
  90.     print "Found in directory: ";sD$;
  91.     locate 13,15
  92.     print "Press any key to continue search";
  93. 250 if inkey$="" then goto 250
  94.     locate 13,15
  95.     print "                                ";
  96.    end if
  97.  
  98.    rem
  99.    rem If we wanted to look for text in file open it here and search
  100.    rem
  101.  
  102.     if inkey$<>"" then stop
  103.     ffname$ = DIR$
  104.     GOTO nextfile
  105.   END IF
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112. rem
  113. rem out of files at this level, look for next subdirectory at this level
  114. rem
  115.  
  116. lookforsub:
  117.  
  118.      if direc(dlevel)=0 then
  119.  
  120.     rem
  121.     rem Look for first sub directory from this level
  122.     rem
  123.  
  124.      sd$=firstlevel$
  125.      for i=1 to dlevel
  126.         sd$=sd$+direcname$(i)+"\"
  127.      next i
  128.      direc(dlevel)=1
  129.      ffname$ = DIR$(sd$+"*.*",5)
  130.      if ffname$="." then
  131.        ffname$ = DIR$
  132.      end if
  133.      if ffname$=".." then
  134.        ffname$=dir$
  135.      end if
  136.  
  137.      else
  138.  
  139.     rem
  140.     rem Look for next sub directory from this level
  141.     rem
  142.      sd$=firstlevel$
  143.      for i=1 to dlevel
  144.         sd$=sd$+direcname$(i)+"\"
  145.      next i
  146.      direc(dlevel)=direc(dlevel)+1
  147.      ffname$=dir$(sd$+"*.*",5)
  148.      if ffname$="." then
  149.        ffname$=dir$
  150.      end if
  151.      if ffname$=".." then
  152.        ffname$=dir$
  153.      end if
  154.      for i=2 to direc(dlevel)
  155.        ffname$=dir$
  156.      next i
  157.      end if
  158.  
  159.      if ffname$="" then
  160.     
  161.     rem
  162.     rem come here if no more sub directories at this level
  163.     rem
  164.     direc(dlevel)=0
  165.     direcname$(dlevel)=""
  166.     dlevel=dlevel-1
  167.     if dlevel>=0 then goto lookforsub
  168.  
  169.     rem
  170.     rem come here if no more directories at all
  171.     rem
  172.         beep
  173.         beep
  174.         locate 12,15
  175.         print "Search Completed .  ";numfiles;" files searched ";numfound;" found.";
  176. 400         if inkey$="" then goto 400
  177.         stop
  178.  
  179.  
  180.      else
  181.  
  182.     rem
  183.     rem come here if have another sub-directory at this level
  184.     rem
  185.     dlevel=dlevel+1
  186.     direcname$(dlevel)=ffname$
  187.     goto newdirectory
  188.  
  189.      end if
  190.  
  191.