Fix export_index.py crash when using filenames without directories #4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
export_index.py
tool was crashing when provided with simple filenames instead of full directory paths. For example:Root Cause
When a filename without directory separators is provided (like
templates.json
),os.path.dirname()
returns an empty string. The code was then callingos.makedirs('')
which fails with:Solution
Modified both
write_csv()
andwrite_json()
functions to only callos.makedirs()
when the directory path is non-empty. This preserves the existing behavior for paths with directories while fixing the crash for simple filenames.Changes
write_csv()
before callingos.makedirs()
write_json()
before callingos.makedirs()
Testing
templates.json
,data.csv
output/templates.json
,data/export.csv
nested/deep/path/file.json
This is a minimal, backward-compatible fix that makes the tool more user-friendly by supporting the most common use case of exporting to the current directory.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.