Meetup: Wildcard Wizards Date: 2024-10-05
You're tasked with creating a file system navigator for a Unix-like system. The navigator should parse a list of file paths and generate a structured representation of the file system.
Write a script that takes a list of file paths as input and produces a nested dictionary representing the file system structure. Each file should be represented as a dictionary/hash with metadata including type, size, date, and time.
No imports allowed. Except for final line for Data Dumper / pprint.
Bonus points for conciseness.
Input will be a list of strings, each representing a file path.
Output should be a nested dictionary/hash representing the file system structure.
No AI or internet help - this must be solved by human hands!
x
/home/user/documents/report.txt^15360^2024-09-28^14:30:22^text
/home/user/documents/meeting_notes.docx^24576^2024-10-01^09:45:13^document
/home/user/documents/budget_2024.xlsx^51200^2024-09-30^16:20:05^spreadsheet
/home/user/documents/project/code.pl^4096^2024-10-03^11:55:30^code
/home/user/documents/project/readme.md^2048^2024-10-02^08:15:44^markdown
/home/user/documents/project/data/input.csv^102400^2024-09-29^10:30:18^csv
/home/user/documents/project/data/output.json^81920^2024-10-03^15:40:27^json
/home/user/downloads/image.jpg^2097152^2024-09-25^18:05:33^image
/home/user/downloads/presentation.pptx^5242880^2024-10-01^11:20:09^presentation
/home/user/downloads/software_v2.3.zip^104857600^2024-09-27^22:15:50^archive
/home/user/pictures/vacation/beach.png^3145728^2024-08-15^09:30:12^image
/home/user/pictures/vacation/sunset.jpg^2621440^2024-08-15^19:45:23^image
/home/user/pictures/family_reunion.jpg^4194304^2024-09-05^14:20:36^image
/home/user/music/playlist1/song1.mp3^5242880^2024-09-10^08:55:17^audio
/home/user/music/playlist1/song2.mp3^4718592^2024-09-10^09:00:05^audio
/home/user/music/audiobook/chapter1.m4a^15728640^2024-09-20^21:30:44^audio
/home/user/.config/app_settings.ini^1024^2024-09-15^12:10:33^config
/home/user/.ssh/id_rsa^1536^2024-07-01^10:00:00^key
/home/user/.ssh/id_rsa.pub^512^2024-07-01^10:00:00^key
/var/log/system.log^1048576^2024-10-04^23:59:59^log
/var/log/apache2/access.log^5242880^2024-10-04^23:59:58^log
/var/log/apache2/error.log^1048576^2024-10-04^23:59:57^log
/var/log/mysql/mysql-slow.log^2097152^2024-10-04^23:59:56^log
/etc/config/settings.conf^4096^2024-09-01^00:00:00^config
/etc/nginx/nginx.conf^8192^2024-09-15^14:30:00^config
/etc/ssh/sshd_config^3072^2024-08-30^11:45:22^config
/etc/cron.d/backup_script^1024^2024-09-10^03:00:00^script
/usr/local/bin/custom_script.sh^2048^2024-09-25^16:40:12^script
/opt/application/app.jar^52428800^2024-09-28^09:15:30^java
/opt/application/config/database.yml^2048^2024-09-28^09:15:31^config
/tmp/temp_file.tmp^10240^2024-10-04^20:45:18^temporary
/root/.bashrc^4096^2024-08-01^00:00:00^config
/root/important_backups/db_dump_20240304.sql^104857600^2024-03-04^03:00:00^database
xxxxxxxxxx
{
'home': {
'user': {
'documents': [
{
'type': 'report.txt',
'file': 'text',
'time': '15360',
'date': '2024-09-28',
'size': '14:30:22'
},
{
'type': 'meeting_notes.docx',
'file': 'document',
'time': '24576',
'date': '2024-10-01',
'size': '09:45:13'
}
],
'downloads': [
{
'type': 'image.jpg',
'file': 'image',
'time': '2097152',
'date': '2024-09-25',
'size': '18:05:33'
}
]
}
},
'var': {
'log': [
{
'type': 'system.log',
'file': 'log',
'time': '1048576',
'date': '2024-10-04',
'size': '23:59:59'
}
]
},
'etc': {
'nginx': [
{
'type': 'nginx.conf',
'file': 'config',
'time': '8192',
'date': '2024-09-15',
'size': '14:30:00'
}
]
},
'tmp': [
{
'type': 'temp_file.tmp',
'file': 'temporary',
'time': '10240',
'date': '2024-10-04',
'size': '20:45:18'
}
]
}
Correctness: The solution must correctly parse the input and generate the required output structure.
Conciseness: Shorter, more elegant solutions will be favored.
Efficiency: The solution should be able to handle large inputs efficiently.
Adherence to requirements: No imports should be used.
Good luck!