bug: FilePicker initial_directory is ignored when opening in subfolder with same name as parent
Duplicate Check
- [x] I have searched the opened issues and there are no duplicates
Describe the bug
Description: When using Flet’s FilePicker with the initial_directory parameter set to a subfolder (e.g., modern_scraper/modern_scraper), the picker always opens in the parent folder (modern_scraper), even though the correct path is passed. This happens even when logging confirms the correct directory is being set and passed to the picker.
Additional info: Logging confirms the correct path is passed. This may be related to the folder name being the same as the parent, or a limitation in the Flet or OS dialog.
Code sample
Code
import flet as ft
from pathlib import Path
def main(page: ft.Page):
data_dir = str(Path(__file__).parent / "modern_scraper")
def on_result(e):
print(f"Picker result: {e.files}, {e.path}")
picker = ft.FilePicker(on_result=on_result)
page.overlay.append(picker)
def open_picker(e):
print(f"Opening picker with initial_directory: {data_dir}")
picker.pick_files(
allowed_extensions=["csv"],
dialog_title="Select Output File Location",
initial_directory=data_dir,
)
page.add(ft.ElevatedButton("Browse", on_click=open_picker))
ft.app(target=main)
To reproduce
Ensure you have a folder structure like parent/child/ where both have the same name (e.g., modern_scraper/modern_scraper). Run the above code from the parent directory. Click “Browse”. The picker opens in the parent, not the intended subfolder.
Expected behavior
The picker should open in the directory specified by initial_directory.
Screenshots / Videos
Captures
[Upload media here]
Operating System
Linux
Operating system details
Ubuntu 24.04.3 LTS x86_64
Flet version
0.23.0
Regression
No, it isn't
Suggestions
Ensure that the initial_directory parameter in FilePicker.pick_files() (and save_file()) is always respected, even when:
The directory has the same name as its parent (e.g., modern_scraper/modern_scraper) The path is an absolute path, not just a relative one The picker is opened multiple times in the same session If the underlying OS dialog or web implementation has limitations, add logic in Flet to:
Normalize and resolve the initial_directory to its absolute path before passing to the dialog Add extra checks to avoid fallback to the parent directory when the intended directory exists and is accessible Provide clear error or warning messages if the directory cannot be set as requested Add automated tests for initial_directory with nested folders of the same name, and verify the picker opens in the correct location.
Logs
Logs
Python3 -m modern_scraper.gui.app
2025-11-18 21:25:25.793 | INFO | modern_scraper.core.registry:register:43 - Registered project: G2S Equipment (g2s)
2025-11-18 21:25:25.794 | INFO | modern_scraper.core.registry:discover_projects:140 - Discovered 1 projects from /home/guido/Dropbox/Programming/Python/modern_scraper/modern_scraper/projects
2025-11-18 21:25:26.180 | WARNING | modern_scraper.core.registry:register:40 - Project 'g2s' already registered, overwriting
2025-11-18 21:25:26.180 | INFO | modern_scraper.core.registry:register:43 - Registered project: G2S Equipment (g2s)
2025-11-18 21:25:26.180 | INFO | modern_scraper.core.registry:discover_projects:140 - Discovered 1 projects from /home/guido/Dropbox/Programming/Python/modern_scraper/modern_scraper/projects
2025-11-18 21:25:27.983 | INFO | modern_scraper.gui.views.scraper:_on_project_changed:427 - Project changed to: g2s
2025-11-18 21:25:27.983 | INFO | modern_scraper.gui.views.scraper:_on_project_changed:431 - Views cache available: True
2025-11-18 21:25:27.983 | INFO | modern_scraper.gui.views.scraper:_on_project_changed:438 - WebsiteConfigView not found, creating it...
2025-11-18 21:25:27.983 | INFO | modern_scraper.gui.views.scraper:_on_project_changed:444 - WebsiteConfigView found: True
2025-11-18 21:25:27.983 | INFO | modern_scraper.gui.views.website_config:set_selected_project:1017 - set_selected_project called with: g2s
2025-11-18 21:25:27.983 | INFO | modern_scraper.gui.views.website_config:set_selected_project:1019 - pending_project_id set to: g2s
2025-11-18 21:25:27.983 | INFO | modern_scraper.gui.views.scraper:_on_project_changed:447 - Synced project 'g2s' to Project Config page
2025-11-18 21:25:33.776 | INFO | modern_scraper.gui.views.scraper:_on_input_file_selected:279 - Input file selected: /home/guido/Dropbox/Programming/Python/modern_scraper/modern_scraper/Scrape List 1 email test.csv
2025-11-18 21:25:33.776 | INFO | modern_scraper.gui.views.scraper:_on_input_file_selected:280 - Updated current_directory to: /home/guido/Dropbox/Programming/Python/modern_scraper/modern_scraper
2025-11-18 21:25:35.154 | INFO | modern_scraper.gui.views.scraper:_on_output_picker_clicked:288 - [PICKER] About to open output picker. self.current_directory = /home/guido/Dropbox/Programming/Python/modern_scraper/modern_scraper
2025-11-18 21:25:35.154 | INFO | modern_scraper.gui.views.scraper:_on_output_picker_clicked:289 - [PICKER] data_directory = /home/guido/Dropbox/Programming/Python/modern_scraper/modern_scraper/gui
2025-11-18 21:25:38.349 | INFO | modern_scraper.gui.views.scraper:_on_output_file_selected:298 - Output file picker result: files=[FilePickerFile(name='Oct Scrape email test (1).csv', path='/home/guido/Dropbox/Programming/Python/modern_scraper/modern_scraper/Oct Scrape email test (1).csv', size=1838, id=0)], path=None
2025-11-18 21:25:38.350 | INFO | modern_scraper.gui.views.scraper:_on_output_file_selected:308 - Selected output path: /home/guido/Dropbox/Programming/Python/modern_scraper/modern_scraper/Oct Scrape email test (1).csv, exists: True
2025-11-18 21:25:38.350 | INFO | modern_scraper.gui.views.scraper:_on_output_file_selected:312 - File exists, showing overwrite dialog
2025-11-18 21:25:38.351 | INFO | modern_scraper.gui.views.scraper:_show_overwrite_dialog:387 - Overwrite dialog added to overlay
2025-11-18 21:25:39.543 | INFO | modern_scraper.gui.views.scraper:on_yes:346 - Overwrite button clicked
2025-11-18 21:25:39.545 | INFO | modern_scraper.gui.views.scraper:on_yes:351 - Calling on_result(True)
2025-11-18 21:25:39.545 | INFO | modern_scraper.gui.views.scraper:on_dialog_result:315 - Overwrite dialog result: True
2025-11-18 21:25:39.545 | INFO | modern_scraper.gui.views.scraper:on_dialog_result:320 - [PICKER] After overwrite, self.current_directory set to: /home/guido/Dropbox/Programming/Python/modern_scraper/modern_scraper
2025-11-18 21:25:39.545 | INFO | modern_scraper.gui.views.scraper:on_dialog_result:321 - Output file set to: /home/guido/Dropbox/Programming/Python/modern_scraper/modern_scraper/Oct Scrape email test (1).csv
2025-11-18 21:25:39.545 | INFO | modern_scraper.gui.views.scraper:on_dialog_result:322 - Setting output_text.value to: /home/guido/Dropbox/Programming/Python/modern_scraper/modern_scraper/Oct Scrape email test (1).csv
2025-11-18 21:25:39.545 | INFO | modern_scraper.gui.views.scraper:on_dialog_result:324 - output_text.value is now: /home/guido/Dropbox/Programming/Python/modern_scraper/modern_scraper/Oct Scrape email test (1).csv
2025-11-18 21:25:39.545 | INFO | modern_scraper.gui.views.scraper:on_dialog_result:326 - Calling page.update()
2025-11-18 21:25:39.546 | INFO | modern_scraper.gui.views.scraper:on_dialog_result:328 - page.update() completed
Additional details
This issue occurs specifically when the target directory has the same name as its parent (e.g., modern_scraper/modern_scraper). The problem is reproducible on Linux . The correct absolute path is always passed to initial_directory (see logs above), but the picker still opens in the parent directory. The issue persists regardless of whether the directory is selected via code initialization or updated dynamically after file selection. No errors or warnings are shown in the console or logs. The behavior is consistent across multiple runs and after restarting the app. Other directories (with unique names) do not exhibit this problem; the picker opens as expected. The issue may be related to how the file picker resolves or normalizes paths with repeated folder names.