DBF File Processor Skill
Process DBF (dBase/FoxPro) files with comprehensive read/write capabilities.
Core Capabilities
- Read DBF files - Extract data and metadata from DBF files
- Write DBF files - Create new DBF files or modify existing ones
- Convert formats - Export DBF to CSV or Excel, import from CSV
- Filter & query - Search, filter, and query DBF records
- Validate structure - Check DBF file integrity and schema
- Edit records - Modify or append records to DBF files
Prerequisites
Install required Python packages:
pip install dbfread dbf pandas openpyxl
Available Scripts
All executable code is located in the scripts/ directory:
| Script | Purpose |
|--------|---------|
| read_dbf.py | Read and display DBF file metadata and sample records |
| dbf_to_csv.py | Convert DBF file to CSV format |
| dbf_to_excel.py | Convert DBF file to Excel format |
| filter_dbf.py | Filter and query records from a DBF file |
| validate_dbf.py | Validate DBF file structure and integrity |
| create_dbf.py | Create a new DBF file with specified structure |
| edit_dbf.py | Edit existing records or append new ones |
| security_utils.py | Security utilities for safe file handling |
Common Workflows
1. Read a DBF File
Input: User asks to read or inspect a DBF file Action:
- Use the
scripts/read_dbf.pyscript - Display basic metadata (field names, types, record count)
- Show a sample of the data (first 5-10 records)
Example:
python scripts/read_dbf.py path/to/file.dbf utf-8 5
2. Convert DBF to CSV
Input: User wants to convert DBF to CSV
Action: Use scripts/dbf_to_csv.py
Example:
python scripts/dbf_to_csv.py input.dbf output.csv utf-8
3. Convert DBF to Excel
Input: User wants to convert DBF to Excel
Action: Use scripts/dbf_to_excel.py
Example:
python scripts/dbf_to_excel.py input.dbf output.xlsx utf-8
4. Filter/Query DBF Data
Input: User wants to filter or query specific records
Action: Use scripts/filter_dbf.py
Example:
# Equals comparison
python scripts/filter_dbf.py data.dbf STATUS ACTIVE equals utf-8
# Contains comparison
python scripts/filter_dbf.py data.dbf NAME "John" contains utf-8
5. Validate DBF Structure
Input: User wants to check DBF file integrity or schema
Action: Use scripts/validate_dbf.py
Example:
python scripts/validate_dbf.py file.dbf utf-8
6. Create/Write DBF File
Input: User wants to create a new DBF file or write data
Action: Use scripts/create_dbf.py
Example:
python scripts/create_dbf.py output.dbf 'NAME C(50)' 'AGE N(3,0)' 'EMAIL C(100)' 'ACTIVE L'
7. Edit/Append Records
Input: User wants to modify existing records or add new ones
Action: Use scripts/edit_dbf.py
Example:
# Append a single record
python scripts/edit_dbf.py existing.dbf append "New Name" 30 "email@example.com" True
# Append from JSON file
python scripts/edit_dbf.py existing.dbf append_json records.json
Encoding Considerations
DBF files often use specific encodings. Common encodings to try:
'utf-8'- Standard UTF-8'latin-1'- Western European'cp1252'- Windows Latin-1'gbk'- Chinese simplified'cp850'- DOS Latin-1
If you encounter encoding errors, try different encodings.
Security Best Practices
When working with DBF files, always follow these security guidelines:
- Validate File Inputs - Use
security_utils.pyfor safe file path handling - Avoid Executing Code - Never use
exec()oreval()with data from DBF files - Sanitize Outputs - Sanitize data when exporting to other formats
- Use Principle of Least Privilege - Run scripts with minimum permissions needed
- Backup Before Modifications - Always create backups before modifying DBF files
See scripts/security_utils.py for security utilities and examples.
Progressive Disclosure
When the user asks about DBF files:
- First understand what they want to accomplish (read, write, convert, etc.)
- Ask for the file path if not provided
- Offer to show metadata first, then sample data
- Ask about specific filters or transformations needed
- Point them to the appropriate script in the
scripts/directory
Scan to join WeChat group