Skip to content

feat(file_organization): enhance file type dictionary and improve error handling #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

daharupesh
Copy link

  • Rename parent_folders to file_types for better clarity
  • Define file types and associated extensions/file names for easier customization
  • Add error handling for non-existent file paths
  • Improve function documentation for better readability and maintainability
  • Wrap main() function call inside if __name__ == '__main__': block to ensure proper script execution

…or handling

- Rename parent_folders to ile_types for better clarity
- Define file types and associated extensions/file names for easier customization
- Add error handling for non-existent file paths
- Improve function documentation for better readability and maintainability
- Wrap main() function call inside if __name__ == '__main__': block to ensure proper script execution
@sanjaysah101 sanjaysah101 self-requested a review September 7, 2024 18:49
Comment on lines 3 to 45
# Define the file types and their associated extensions and file names
file_types = {
'Images': {
'Extensions': ['ai', 'bmb', 'gif', 'ico', 'jpeg', 'jpg', 'max', 'obj', 'png', 'ps', 'psd', 'svg', 'tif', 'tiff', '3ds', '3dm'],
'File Names': ['AI Image (ai)', 'Bitmap Image (bmb)', 'Graphics Interchange Format (gif)', 'Icon File (ico)', 'Joint Photographic Experts Group (jpeg)', 'JPEG Image (jpg)', 'Autodesk 3ds Max Scene (max)', 'Wavefront OBJ File (obj)', 'Portable Network Graphics (png)', 'PostScript (ps)', 'Photoshop Document (psd)', 'Scalable Vector Graphics (svg)', 'Tagged Image File Format (tif)', 'TIFF Image (tiff)', '3D Studio Scene (3ds)', 'Rhino 3D Model (3dm)']
},
'Text Files': {
'Extensions': ['doc', 'docx', 'odt', 'msg', 'pdf', 'rtf', 'tex', 'txt', 'wks', 'wps', 'wpd'],
'File Names': ['Word Document (doc)', 'Word Document (docx)', 'Open Document Text (odt)', 'Outlook Message (msg)', 'Portable Document Format (pdf)', 'Rich Text Format (rtf)', 'LaTeX Document (tex)', 'Plain Text (txt)', 'Microsoft Works Document (wks)', 'Microsoft Works Document (wps)', 'WordPerfect Document (wpd)']
},
'Executable Files': {
'Extensions': ['apk', 'bat', 'bin', 'cgi', 'com', 'exe', 'jar', 'py', 'wsf', 'ipynb'],
'File Names': ['Android Package (apk)', 'Batch File (bat)', 'Binary File (bin)', 'Common Gateway Interface Script (cgi)', 'Command File (com)', 'Executable File (exe)', 'Java Archive (jar)', 'Python Script (py)', 'Windows Script File (wsf)', 'Jupyter Notebook (ipynb)']
},
'Audio Files': {
'Extensions': ['aif', 'cda', 'iff', 'mid', 'midi', 'mp3', 'mpa', 'wav', 'wma', '3g2', '3gp'],
'File Names': ['Audio Interchange File Format (aif)', 'Compact Disc Audio Track (cda)', 'Interchange File Format (iff)', 'MIDI File (mid)', 'MIDI File (midi)', 'MP3 Audio File (mp3)', 'MPEG Audio (mpa)', 'Waveform Audio File Format (wav)', 'Windows Media Audio (wma)', '3GPP2 Multimedia File (3g2)', '3GPP Multimedia File (3gp)']
},
'Video Files': {
'Extensions': ['mp4', 'avi', 'flv', 'mkv', 'mov', 'wmv'],
'File Names': ['MPEG-4 Video File (mp4)', 'Audio Video Interleave (avi)', 'Flash Video (flv)', 'Matroska Video File (mkv)', 'Apple QuickTime Movie (mov)', 'Windows Media Video (wmv)']
},
'Spreadsheets': {
'Extensions': ['ods', 'xlr', 'xls', 'xlsx'],
'File Names': ['OpenDocument Spreadsheet (ods)', 'Microsoft Works Spreadsheet (xlr)', 'Microsoft Excel Spreadsheet (xls)', 'Microsoft Excel Spreadsheet (xlsx)']
},
'Presentations': {
'Extensions': ['key', 'odp', 'pps', 'ppt', 'pptx'],
'File Names': ['Keynote Presentation (key)', 'OpenDocument Presentation (odp)', 'PowerPoint Slide Show (pps)', 'PowerPoint Presentation (ppt)', 'PowerPoint Presentation (pptx)']
},
'Database Files': {
'Extensions': ['accdb', 'csv', 'dat', 'db', 'dbf', 'log', 'mdb', 'pdb', 'sav', 'sql', 'tar'],
'File Names': ['Access Database (accdb)', 'Comma-Separated Values (csv)', 'Data File (dat)', 'Database File (db)', 'Database File (dbf)', 'Log File (log)', 'Microsoft Database (mdb)', 'Palm Desktop Database (pdb)', 'SPSS Data File (sav)', 'Structured Query Language (sql)', 'Tape Archive (tar)']
},
'Web Files': {
'Extensions': ['asp', 'aspx', 'cer', 'cfm', 'cgi', 'pl', 'css', 'htm', 'html', 'js', 'part', 'php', 'rss', 'xhtml'],
'File Names': ['Active Server Pages (asp)', 'Active Server Page Executable (aspx)', 'Security Certificate (cer)', 'ColdFusion Markup Language File (cfm)', 'Common Gateway Interface Script (cgi)', 'Perl Script (pl)', 'Cascading Style Sheet (css)', 'Hypertext Markup Language (htm)', 'Hypertext Markup Language (html)', 'JavaScript File (js)', 'Partially Downloaded File (part)', 'Hypertext Preprocessor (php)', 'Really Simple Syndication (rss)', 'Extensible Hypertext Markup Language (xhtml)']
},
'System Files': {
'Extensions': ['bak', 'cab', 'cfg', 'cpl', 'cur', 'dll', 'dmp', 'drv', 'icns', 'ico', 'ini', 'lnk', 'msi', 'sys', 'tmp'],
'File Names': ['Backup File (bak)', 'Windows Cabinet File (cab)', 'Configuration File (cfg)', 'Control Panel Extension (cpl)', 'Cursor File (cur)', 'Dynamic Link Library (dll)', 'Dump File (dmp)', 'Device Driver (drv)', 'Icon File (icns)', 'Icon File (ico)', 'Configuration File (ini)', 'Shortcut (lnk)', 'Windows Installer Package (msi)', 'System File (sys)', 'Temporary File (tmp)']
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @daharupesh,

To improve the separation of concerns and enhance code readability and maintainability, we can create a separate fileTypes.json file. This will allow us to store file type information separately from the code logic. You can use Pandas to read the JSON file, ensuring that the data is handled efficiently and cleanly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sanjaysah101 ,

Thank you for the suggestion. That’s a great idea! I'll create a fileTypes.json file to separate the file type information from the code logic. Using Pandas to read the JSON file will certainly improve the maintainability and readability of the code. I'll implement these changes and push the updates soon.

Comment on lines +49 to +55
'''
Get the folder path from the user.
This function prompts the user to enter a folder path, checks if the path exists, and returns the path if valid.

Returns:
path (str): The valid folder path entered by the user.
'''
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_path function can throw an error. Please update the function docs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out. I'll update the get_path function documentation to include the potential errors it might throw. This will help ensure better error handling and clarity for future development. I’ll push the changes soon!

… improved separation of concerns

- Extracted file type data into a dedicated fileTypes.json to enhance code readability and maintainability.
- Updated the logic to use Pandas for efficient and clean handling of JSON data.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants