Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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)
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
You can’t perform that action at this time.