home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_std / file_tools.e < prev    next >
Text File  |  1999-06-05  |  3KB  |  123 lines

  1. -- This file is  free  software, which  comes  along  with  SmallEiffel. This
  2. -- software  is  distributed  in the hope that it will be useful, but WITHOUT 
  3. -- ANY  WARRANTY;  without  even  the  implied warranty of MERCHANTABILITY or
  4. -- FITNESS  FOR A PARTICULAR PURPOSE. You can modify it as you want, provided
  5. -- this header is kept unaltered, and a notification of the changes is added.
  6. -- You  are  allowed  to  redistribute  it and sell it, alone or as a part of 
  7. -- another product.
  8. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  9. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  10. --                       http://SmallEiffel.loria.fr
  11. --
  12. expanded class FILE_TOOLS
  13.  
  14. inherit ANY;
  15.  
  16. feature
  17.  
  18.    same_files(path1, path2: STRING): BOOLEAN is
  19.          -- True if `path1' file exists and as the 
  20.          -- same contents as file `path2'.
  21.       require else
  22.          path1 /= Void;
  23.          path2 /= Void
  24.       do
  25.          std_fr1.connect_to(path1);
  26.          if std_fr1.is_connected then
  27.             std_fr2.connect_to(path2);
  28.             if std_fr2.is_connected then
  29.                Result := std_fr1.same_as(std_fr2);
  30.             end;
  31.          else 
  32.             std_fr1.disconnect;
  33.          end;
  34.       end;
  35.  
  36.    is_readable(path: STRING): BOOLEAN is
  37.       require
  38.          path /= Void
  39.          -- True if `path' file exists and is a readable file.
  40.       do
  41.          std_fr1.connect_to(path);
  42.          Result := std_fr1.is_connected;
  43.          if Result then
  44.             std_fr1.disconnect;
  45.          end;
  46.       end;
  47.  
  48.    is_empty(path: STRING): BOOLEAN is
  49.          -- True if `path' file exists, is readable and is an 
  50.          -- empty file.
  51.       do
  52.          std_fr1.connect_to(path);
  53.          if std_fr1.is_connected then
  54.             std_fr1.read_character;
  55.             Result := std_fr1.end_of_input;
  56.             std_fr1.disconnect;
  57.          end;
  58.       end;
  59.  
  60.    rename_to(old_path, new_path: STRING) is
  61.       require
  62.          old_path /= Void;
  63.          new_path /= Void
  64.       local
  65.          p1, p2: POINTER;
  66.       do
  67.          if file_exists(new_path) then
  68.             delete(new_path);
  69.          end;
  70.          p1 := old_path.to_external;
  71.          p2 := new_path.to_external;
  72.          se_rename(p1,p2);
  73.       end;
  74.  
  75.    delete(path: STRING) is
  76.       require
  77.          path /= Void
  78.       local
  79.          p: POINTER;
  80.       do
  81.          p := path.to_external;
  82.          se_remove(p);
  83.       end;
  84.  
  85.    mkdir(name: STRING) is
  86.       local
  87.          p: POINTER;
  88.       do
  89.          p := name.to_external;
  90.          c_inline_c("mkdir((char*)_p,511);");
  91.       end;
  92.  
  93. feature {NONE}
  94.  
  95.    se_remove(path: POINTER) is
  96.          -- To implement `delete'.
  97.       external "SmallEiffel"
  98.       end;
  99.  
  100.    se_rename(old_path, new_path: POINTER) is
  101.       external "SmallEiffel"
  102.       end;
  103.  
  104.    std_fr1: STD_FILE_READ is
  105.       once
  106.          !!Result.make;
  107.       end;
  108.  
  109.    std_fr2: STD_FILE_READ is
  110.       once
  111.          !!Result.make;
  112.       end;
  113.  
  114. feature {NONE}
  115.    
  116.    tmp_string: STRING is
  117.       once
  118.          !!Result.make(256);
  119.       end;
  120.  
  121. end -- FILE_TOOLS
  122.  
  123.