Brian Hulley wrote:
rename extFrom extTo files = do
let candidates = filter (\(_,ext) -> ext==extFrom) (map split
files)
mapM_ (\f@(n,_) -> rename (unsplit f) (unsplit (n, extTo)))
candidates
% ls >>= rename "txt" "hs"
I see I've used the same name twice...;-) It should be:
ren extFrom extTo files = do
let candidates = filter
(\(_,ext) -> ext==extFrom)
(map split files)
mapM_
(\f@(n,_) ->
rename (unsplit f) (unsplit (n, extTo)))
candidates
% ls >>= ren "txt" "hs"
Of course a better choice of primitive commands would give a more powerful
shell interface eg using:
renif extFrom extTo fileName =
case split fileName of
(n, ext) | ext == extFrom -> rename fileName (unsplit (n,
extTo))
_ -> return ()
% ls >>= mapM_ (renif "txt" "hs")
Regards, Brian.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe