file_info now returns a string that does not contain the path/filename
authorclasohm
Fri, 15 Oct 1993 12:51:21 +0100
changeset 58 b30802dfbe80
parent 57 87e14d7f20dc
child 59 ab555029f583
file_info now returns a string that does not contain the path/filename (so the string doesn't change when the relative path does)
src/Pure/POLY.ML
--- a/src/Pure/POLY.ML	Fri Oct 15 12:49:33 1993 +0100
+++ b/src/Pure/POLY.ML	Fri Oct 15 12:51:21 1993 +0100
@@ -38,12 +38,24 @@
 
 (*** File information ***)
 
-(*Get time of last modification.*)
+(*Get a string containing the time of last modification, attributes, owner
+  and size of file (but not the path) *)
 fun file_info "" = ""
   | file_info name =
-        let val (is, os) = ExtendedIO.execute ("ls -l " ^ name)
-            val result = ExtendedIO.input_line is;
-            val dummy = close_in is;
-            val dummy = close_out os;
-        in result end;
+      let
+          (*These are functions from library.ML *)
+          fun take_suffix _ [] = ([], [])
+            | take_suffix pred (x :: xs) =
+                (case take_suffix pred xs of
+                  ([], sffx) => if pred x then ([], x :: sffx) else ([x], sffx)
+                | (prfx, sffx) => (x :: prfx, sffx));
+          fun apr (f,y) x = f(x,y);
 
+          val (is, os) = ExtendedIO.execute ("ls -l " ^ name)
+          val (result, _) = take_suffix (apr(op<>," ")) 
+                              (explode (ExtendedIO.input_line is))
+                (*Remove the part after the last " " (i.e. the path/filename) *)
+        in close_in is;
+           close_out os;
+           implode result
+        end;