Skip to content

Instantly share code, notes, and snippets.

@michaelsproul
Created April 26, 2015 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelsproul/88fbd0a39daa463c2189 to your computer and use it in GitHub Desktop.
Save michaelsproul/88fbd0a39daa463c2189 to your computer and use it in GitHub Desktop.
Haskell File Rename
-- 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