Dosya Varlığı Kontrolü
package main
import (
"fmt"
"os"
)
func main() {
if d := "dosya.txt"; dosyaVarmı(d) {
fmt.Println(d, "bulunuyor")
} else {
fmt.Println(d, "bulunmuyor!")
}
}
func dosyaVarmı(isim string) bool {
bilgi, hata := os.Stat(isim)
if os.IsNotExist(hata) {
return false
}
return !bilgi.IsDir()
}Last updated