awesome-go/impl/files-manipulation/07-CheckFileExist.go

30 lines
461 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"log"
"os"
)
var (
fileInfo *os.FileInfo
err error
)
func main() {
/*
Dosyanın var olup olmadığını kontrol etmek (Check if File Exists)
*/
// Dosya bilgisini döndürür.
// Eğer dosya yoksa hata döndürür.
fileInfo, err := os.Stat("demo.txt")
if err != nil {
if os.IsNotExist(err) {
log.Fatal("File does not exist")
}
}
log.Println("File does exist. File information : ")
log.Println(fileInfo)
}