Skip to content

Commit 123c169

Browse files
committed
add Haskell snippet to check if a file exists
1 parent 331371e commit 123c169

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Check if File Exists
3+
description: Checks if a file exists at a given path.
4+
author: ACR1209
5+
tags: haskell,file,exists
6+
---
7+
8+
```hs
9+
import System.Directory (doesFileExist)
10+
11+
checkFileExists :: FilePath -> IO Bool
12+
checkFileExists = doesFileExist
13+
14+
main :: IO ()
15+
main = do
16+
let file = "example.txt"
17+
exists <- checkFileExists file
18+
if exists then putStrLn "File exists." else putStrLn "File does not exist."
19+
```

0 commit comments

Comments
 (0)