# Dosya Varlığı Kontrolü

Go programımızda kullancağımız bir bir dosyanın varlığını `os` paketi ile kontrol edebiliriz. Örnek programımızı görelim:

```go
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()
}
```

**Gelelim açıklmasına:**

Dosya işlemleri yapabilmek için `os` paketini import ettik. if-else akışında geçici değişken olarak `d` değişkenine `"dosya.txt"` atayarak kontrol edilecek dosyamızın ismini belirledik.

Bu akışta `dosyaVarmı` fonksiyonunda `true` değer dönerse `dosya.txt bulunuyor` olarak çıktı almamız gerekir.

`dosyaVarmı` fonksiyonunu incelediğimizde `bilgi` ve `hata` değişkenlerine `os.Stat` ile dosyanın bilgilerini çektik. `hata` değişkeni `false` döndürürse fonksiyonun `false` döndürmesini istedik. Aynı şekilde `bilgi.IsDir()` ile dosya değil de bir dizinse `false` döndürmesini istedik.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://go.kaanksc.com/bolum-7-dosya-islemleri/dosya-varligi-kontrolue.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
