# P9.1 Python मध्ये File Paths आणि Working Folder

Source: https://ravindrabagale.com/mr/datascience/py09-how-to-read-and-write-csv-json-and-text-files-in-python/p9-1-file-paths-and-the-working-folder-in-python.html
Language: mr (Marathi with English technical terms)

हे का शिकायचं?

"File सापडत नाही" ही सगळ्यात नेहमीची अडचण. Python कुठे शोधतो ते माहीत हवं.

हे काय आहे?

Working folder म्हणजे जिथून Python files शोधतो. os.getcwd() तो दाखवतो. pathlib.Path ने Windows आणि Mac दोन्हीवर चालणारा path बनतो.

कसं करायचं?

Step 1. os.getcwd() ने folder पाहा.
Step 2. Path("data") / "file.csv" ने path बनवा.

उदाहरण A: मी कुठे आहे?

Input file sales.csv:

```text
date,store,item,qty,price
2026-03-01,Pune,Milk,3,56
2026-03-01,Mumbai,Bread,2,40
2026-03-02,Pune,Eggs,1,84
2026-03-02,Nagpur,Milk,5,56
```

```python
from pathlib import Path
p = Path("sales.csv")
print(p.exists())
print(p.suffix)
```

Output:

```text
True
.csv
```

याचा अर्थ: exists() ने file working folder मध्ये आहे का ते तपासलं (True) आणि suffix ने extension (.csv) मिळालं.

उदाहरण B: सुरक्षितपणे path बनवा

```python
from pathlib import Path
p = Path("reports") / "2026" / "march.csv"
print(p.as_posix())
print(p.name, p.stem)
```

Output:

```text
reports/2026/march.csv
march.csv march
```

याचा अर्थ: / ने path जोडला, त्यामुळे slash ची काळजी नको.

रवींद्र बागले यांची tip

Windows वर paths forward slash ने लिहा `C:/data/file.csv` किंवा pathlib वापरा. साध्या strings मधले backslashes विचित्र bugs आणतात.
