generate functionSat, 12 Nov 2022

Filter the files in a directory where the names of the files are numeric strings and create a directory for each file filtered, naming the directories the same with the file, moving the file into the folder and changing the name of the file to "index.svg"

module Main where import System.Directory import System.FilePath import Control.Exception import Data.List main = do createDirectories putStrLn "Done" createDirectories :: IO () createDirectories = do curDir <- getCurrentDirectory files <- (listDirectory curDir) let numFiles = filter isNumber files numDirs = map (curDir </>) numFiles zipped = zip numFiles numDirs createDirAndMoveFile (file, dir) = do createDirectory dir renameFile file (dir </> "index.svg") mapM_ createDirAndMoveFile zipped isNumber :: String -> Bool isNumber s = case reads s :: [(Integer, String)] of [(_, "")] -> True _ -> False

Questions about programming?Chat with your personal AI assistant