This commit is contained in:
rnhmjoj 2015-11-22 03:27:20 +01:00
parent 04d0742ff0
commit e16d17ed72
2 changed files with 6 additions and 5 deletions

View File

@ -8,8 +8,8 @@ import System.FilePath.Posix
import qualified Data.ByteString as B import qualified Data.ByteString as B
getDirectoryFiles :: FilePath -> IO [FilePath] getDirectoryFiles :: FilePath -> IO [FilePath]
getDirectoryFiles path = getDirectoryFiles path = map (path </>) <$>
map (path </>) <$> getDirectoryContents path >>= filterM doesFileExist getDirectoryContents path >>= filterM doesFileExist
fileHash :: FilePath -> IO String fileHash :: FilePath -> IO String
fileHash = fmap (hex . hash) . B.readFile fileHash = fmap (hex . hash) . B.readFile
@ -28,6 +28,7 @@ newName path = do
then return path then return path
else return new else return new
main :: IO ()
main = do main = do
args <- getArgs args <- getArgs
path <- case args of path <- case args of
@ -41,4 +42,4 @@ main = do
y' = takeFileName y y' = takeFileName y
putStrLn (printf "%s -> %s" x' y') putStrLn (printf "%s -> %s" x' y')
renameFile x y renameFile x y
putStrLn "Files renamed successfully" putStrLn "Files renamed successfully"

View File

@ -1,5 +1,5 @@
name: hashrename name: hashrename
version: 0.1.0.0 version: 0.1.1.0
synopsis: Rename every file in a directory with his SHA1 hash. Perfect to clean messy folders. synopsis: Rename every file in a directory with his SHA1 hash. Perfect to clean messy folders.
license: MIT license: MIT
license-file: LICENSE license-file: LICENSE
@ -13,4 +13,4 @@ cabal-version: >=1.10
executable hashrename executable hashrename
main-is: Main.hs main-is: Main.hs
build-depends: base >=4.8 && <4.9, directory, filepath, cryptohash, bytestring build-depends: base >=4.8 && <4.9, directory, filepath, cryptohash, bytestring
default-language: Haskell2010 default-language: Haskell2010