Created
April 26, 2015 13:12
-
-
Save michaelsproul/88fbd0a39daa463c2189 to your computer and use it in GitHub Desktop.
Haskell File Rename
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Even vanilla Haskell is quite nice for scripting. I prefer it to Bash! | |
import System.Directory | |
import System.Posix.Files hiding (rename) | |
main = do | |
currDir <- getCurrentDirectory | |
photos <- getDirectoryContents currDir | |
mapM rename photos | |
rename :: String -> IO () | |
rename x = do | |
stat <- getFileStatus x | |
if isRegularFile stat then | |
renameFile x (newName x) | |
else | |
return () | |
newName :: String -> String | |
newName (d1:d2:'-':m1:m2:'-':y1:y2:'_':rest) = | |
[y1, y2] ++ "-" ++ [m1, m2] ++ "-" ++ [d1, d2] ++ " " ++ rest | |
newName x = x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment