@@ 17,6 17,7 @@
#:use-module ((ice-9 binary-ports) #:prefix i9:)
#:use-module ((ice-9 textual-ports) #:prefix i9:)
#:use-module (srfi srfi-1)
+ #:use-module (ice-9 regex)
#:use-module ((f ports) #:prefix p:)
#:use-module ((f re-exports) #:prefix re:)
#:export (read-bytes
@@ 31,7 32,9 @@
mkdir
delete
traverse
- copy)
+ copy
+ no-extension
+ replace-extension)
#:re-export (chown
chmod
(rename-file . move)
@@ 169,3 172,19 @@ appending a #t at the end."))))))
(throw 'f.scm "Can't copy: directory not empty. Try with making the call recursive
by appending a #t at the end."))))
(copy-file src dest)))
+
+(define (no-extension file)
+ "Return FILE path without extension."
+ (let ((without-ext (string-match "(.+)\\..*" (basename file))))
+ (if without-ext
+ (regexp-substitute #f without-ext 1)
+ file)))
+
+(define (replace-extension file ext)
+ "Replace file extension in FILE with EXT.
+EXT can include or exclude the beginning \".\"."
+ (let ((ext (cond
+ ((string-null? ext) "")
+ ((string-match "^\\..+" ext) ext)
+ (else (string-append "." ext)))))
+ (string-append (no-extension file) ext)))