@@ -16,6 +16,49 @@ depending on the platform.
16
16
17
17
Both "System.FilePath.Posix" and "System.FilePath.Windows" provide the
18
18
same interface.
19
+
20
+ Given the example 'FilePath': @\/directory\/file.ext@
21
+
22
+ We can use the following functions to extract pieces.
23
+
24
+ * 'takeFileName' gives @\"file.ext\"@
25
+
26
+ * 'takeDirectory' gives @\"\/directory\"@
27
+
28
+ * 'takeExtension' gives @\".ext\"@
29
+
30
+ * 'dropExtension' gives @\"\/directory\/file\"@
31
+
32
+ * 'takeBaseName' gives @\"file\"@
33
+
34
+ And we could have built an equivalent path with the following expressions:
35
+
36
+ * @\"\/directory\" '</>' \"file.ext\"@.
37
+
38
+ * @\"\/directory\/file" '<.>' \"ext\"@.
39
+
40
+ * @\"\/directory\/file.txt" '-<.>' \"ext\"@.
41
+
42
+ Each function in this module is documented with several examples,
43
+ which are also used as tests.
44
+
45
+ Here are a few examples of using the @filepath@ functions together:
46
+
47
+ /Example 1:/ Find the possible locations of a Haskell module @Test@ imported from module @Main@:
48
+
49
+ @['replaceFileName' path_to_main \"Test\" '<.>' ext | ext <- [\"hs\",\"lhs\"] ]@
50
+
51
+ /Example 2:/ Download a file from @url@ and save it to disk:
52
+
53
+ @do let file = 'makeValid' url
54
+ System.Directory.createDirectoryIfMissing True ('takeDirectory' file)@
55
+
56
+ /Example 3:/ Compile a Haskell file, putting the @.hi@ file under @interface@:
57
+
58
+ @'takeDirectory' file '</>' \"interface\" '</>' ('takeFileName' file '-<.>' \"hi\")@
59
+
60
+ References:
61
+ [1] <http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247.aspx Naming Files, Paths and Namespaces> (Microsoft MSDN)
19
62
-}
20
63
21
64
0 commit comments