home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / comm / nmodem.zip / TCHD.PAS < prev    next >
Pascal/Delphi Source File  |  1991-01-13  |  7KB  |  136 lines

  1. PROGRAM TCHD;  { (c)Copyright 1990,1991 by L. B. Neal }
  2.  
  3. { This program placed in the Public Domain May 3, 1990   }
  4. { for private personal non-profit use only.              }
  5.  
  6. { TCHD is designed to be a keystroke and time saver for  }
  7. { folks like myself that find a "shell" a bit of a pain. }
  8.  
  9. { I setup PathSearch as a FUNCTION since the code will   }
  10. { probably change when I decide that two levels is NOT   }
  11. { enough.  As far as I know two levels is just about able}
  12. { to cover everything on my HD for now.  I notice shell  }
  13. { users seem to make rat nests of subdirectories but they}
  14. { won't need this utility anyway.                        }
  15.  
  16.  
  17. {$M 4096,0,4096}      { don't need much memory for this guy!     }
  18. {$R-,S-,V-,B-}        { make sure we don't slow things down here }
  19.  
  20. USES DOS,CRT;         { Chdir, FindFirst, Findnext, etc  0.97    }
  21.  
  22. CONST
  23.  Version = ' TCHD Ver:0.97 By L.B. Neal.';
  24.  
  25. TYPE
  26.  Str90 = String[90];                         { we only need max 90 char }            
  27.  
  28. VAR
  29.    DirInfo: SearchRec;                       { storage for FindFirst    }
  30.    passpath : Str90;                         { save command line here   }
  31.    Drive:     String[2];                     { drive letter storage     }
  32.    Switch: Integer;                          { : pos storage value      }
  33.    Home: Str90;                              { we started from here     }
  34.    path: Str90;                              { where we want to get to  }
  35.  
  36.  {---------------------------------------------------------------- }
  37.  { If our quick and dirty search fails we bring up the heavy stuff }
  38.  { This will take us down to the 1st subdir level.                 }
  39.  {---------------------------------------------------------------- }
  40.  
  41.  FUNCTION PathSearch: Boolean;  { added 0.92 }
  42.  VAR Done,TryAnother: Boolean; Dirs,SubList: SearchRec;
  43.  BEGIN
  44.   PathSearch := False; Done := False;       { intialize the variables       }
  45.   FindFirst('*.',Directory,Dirs);           { Start thru all the directories}
  46.   IF DOSERROR = 0 THEN                      { if it worked                  }
  47.    REPEAT
  48.     {$I-}Chdir(Dirs.name);{$I+}             { Move into a directory         }
  49.     IF IORESULT = 0 THEN                    { Just to be safe               }
  50.      BEGIN
  51.       FindFirst(path+'.',Directory,Sublist); { See if target is a subdir   }
  52.       IF DOSERROR = 0 THEN                   { Looks like its here         }
  53.        BEGIN
  54.         TryAnother := False;                { set abort flag              }
  55.         REPEAT
  56.          IF SubList.attr = $10 THEN         { did we find a directory?    }
  57.           BEGIN                             { yes give it a shot          }
  58.            {$I-}ChDir(Sublist.name);{$I+}   { protect ourselves           }
  59.            IF IORESULT = 0 THEN             { we did it!                  }
  60.             BEGIN
  61.              Done := True;                  { Escape from loop            }
  62.              PathSearch := True;            { Return a true to TCHD       }
  63.             END;
  64.           END;
  65.          IF NOT done THEN FindNext(SubList);{ one more time 0.96          }
  66.          IF DOSERROR <> 0 THEN TryAnother := True; { out of trys here!    }
  67.         UNTIL done OR TryAnother;           { till find it or give up     }
  68.        END
  69.       ELSE                                    { it wasn't here!           }
  70.        BEGIN
  71.         ChDir('\');                           { go back into root dir     }
  72.         REPEAT
  73.          FindNext(Dirs);                      { try the next directory    }
  74.          IF DOSERROR <> 0 THEN  Done := True; { out of places to look     }
  75.         UNTIL (dirs.attr = $10) OR Done;      { can we find a dir to try? }
  76.        END;
  77.       END
  78.      ELSE Done := True;                 { somethings wrong here just quit }
  79.    UNTIL Done;                          { try try again till find or quit }
  80.  END;{PathSearch}
  81.  
  82. BEGIN {TCHD}
  83.  
  84.  IF paramcount > 0 THEN                      { see if parameters on line  }
  85.   BEGIN  
  86.    CheckBreak := False;                      { more speed here  0.97      }
  87.    DirectVideo := False;                     { allow redirection,etc 0.97 }
  88.    WriteLn;                                  { move away from prompt      }
  89.    Write(version);                           { issue version statement    }
  90.    Getdir(0,home);                           { remember where we came frm }
  91.    PassPath := paramstr(1);                  { save the command line      }
  92.    Switch := POS(':',PassPath);              { did we get a drive call ?  }
  93.    IF switch > 0 THEN                        { yes lets process it        }
  94.     BEGIN
  95.      Drive := Copy(passpath,1,switch);       { extract drive letter + ':' }
  96.      Write('  Target Drv> ',drive,'  ');     { show user where we're going}
  97.      {$I-}ChDir(drive);{$I+}                 { see if that drive exists   }
  98.      IF IORESULT = 0 THEN                    { yup and we are there       }
  99.       BEGIN                                  { parse out path name        }
  100.        Path := COPY(passpath,switch+1,Length(passpath)-switch);
  101.        Path := path+'*';                     { add a * to path            }
  102.       END;
  103.     END
  104.    ELSE                                      { change is on this drive    }
  105.     path := {BackSlash+}passpath+'*';        { make it 'path*' 0.92       }
  106.    WriteLn('  Target Path> ',Path,'');       { show user were still here  }
  107.    {$I-}Chdir(passpath);{$I+}                { try as typed 0.94          }
  108.    IF IORESULT <> 0 THEN                     { didn't make it 0.94        }
  109.     BEGIN
  110.      {$I-}ChDir(path);{$I+}                  { make a shot at path        }
  111.      IF IORESULT <> 0 THEN                   { didn't work try again      }
  112.       BEGIN
  113.        Chdir('\');                           { move to root directory     }
  114.        Findfirst(path+'.',Directory,Dirinfo); { see if there is such path  }
  115.        IF DosError = 0 THEN                  { yup we found one           }
  116.         BEGIN
  117.          {$I-} Chdir(Dirinfo.name);{$I+}     { move over there            }
  118.          IF IORESULT <> 0 THEN               { try PathSearch 0.94        }
  119.           IF PathSearch THEN {NOP};          { good we found it 0.94      }
  120.         END
  121.        ELSE
  122.         IF PathSearch THEN                   { lets really look now!      }
  123.          {NOP}                               { great we found it!         }
  124.         ELSE
  125.          BEGIN
  126.           WriteLn(' Directory was NOT found!');{ oops we failed             }
  127.           Chdir(home);                         { back to home 0.91          }
  128.          END;
  129.       END;
  130.     END;
  131.   END
  132.  ELSE
  133.   WriteLn(version,'.  Usage: TCHD [drive]path'); { let user know what we need }
  134.  
  135. END.{TCHD}
  136.