mirror of https://github.com/pikami/rss-dl.git
44 lines
777 B
Go
44 lines
777 B
Go
package fileio
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
// WriteToFile - Writes a string to file
|
|
func WriteToFile(filename string, content string) {
|
|
f, err := os.Create(filename)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
l, err := f.WriteString(content)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
f.Close()
|
|
return
|
|
}
|
|
fmt.Println(l, "bytes written successfully")
|
|
err = f.Close()
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
}
|
|
|
|
// InitOutputDirectory - Creates output directory
|
|
func InitOutputDirectory(path string) {
|
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
|
os.MkdirAll(path, os.ModePerm)
|
|
}
|
|
}
|
|
|
|
// CheckIfExists - Checks if file or directory exists
|
|
func CheckIfExists(path string) bool {
|
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|