mirror of
https://github.com/RussellChamp/advent-of-code-2021.git
synced 2026-10-28 06:02:31 +00:00
day 16 part 1
This commit is contained in:
1 parent
4737afa383
commit
0c277a8404
11 files changed
+463
-1
No files matched your search
@@ -0,0 +1,27 @@
|
||||
package files
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func CreateOrReplace(fileName string) (*os.File, error) {
|
||||
var output *os.File
|
||||
if _, err := os.Stat(fileName); errors.Is(err, os.ErrNotExist) {
|
||||
output, err = os.Create(fileName)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error creating file %s", fileName)
|
||||
}
|
||||
} else {
|
||||
err = os.Truncate(fileName, 0)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error truncating file %s", fileName)
|
||||
}
|
||||
output, err = os.Open(fileName)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error opening file %s", fileName)
|
||||
}
|
||||
}
|
||||
return output, nil
|
||||
}
|
||||
Reference in new issue
Block a user