FileMa Library
Overview
The FileMa
library provides utilities for file and directory management in Python. It includes functions for creating, removing, renaming, copying files and directories, as well as reading file contents, printing directory structures, and more. The library uses colored terminal output for better visual feedback.
Installation
Ensure that you have the colorama
library installed. You can install it via pip if it's not already installed:
pip install colorama
Installation FileMa Library
pip install FileMa
Usage
Below are the available functions and how to use them.
File Management
Core Functions
These functions offer a robust set of tools for file management operations, and they include error handling for common issues like file not found or permission errors.
Usage
Import the Library
import FileMa
Available Functions
Here is the usage guide for the FileMa
library functions :
1. Create or Update a File:
FileMa.touch('example.txt')
Description: Creates a new file named example.txt
if it does not already exist. If it does exist, it updates the access time.
2. Remove a File:
FileMa.rm('example.txt')
Description: Removes the file named example.txt
if it exists.
3. Write or Append to a File:
FileMa.nano('example.txt', 'w', 'Hello, World!')
Description: Writes 'Hello, World!' to example.txt
. Use 'a'
instead of 'w'
to append the content instead of overwriting it.
4. Read a File:
FileMa.cat('example.txt')
Description: Displays the contents of example.txt
.
5. Rename a File or Directory:
FileMa.ren('old_name.txt', 'new_name.txt')
Description: Renames old_name.txt
to new_name.txt
.
6. Move a File or Directory:
FileMa.mv('source_path.txt', 'destination_path.txt')
Description: Moves source_path.txt
to destination_path.txt
.
7. Copy Content Between Files:
FileMa.copy('source.txt', 'destination.txt', 'w')
Description: Copies the content of source.txt
to destination.txt
. You can use 'a'
instead of 'w'
to append the content.
8. Copy a File:
FileMa.copyf('source.txt', 'destination.txt')
Description: Copies the file source.txt
to destination.txt
.
9. Create a Directory:
FileMa.mkdir('new_folder')
Description: Creates a new directory named new_folder
.
10. Remove an Empty Directory:
FileMa.rmdir('new_folder')
Description: Removes the empty directory named new_folder
.
11. Copy a Directory:
FileMa.copyd('source_folder', 'destination_folder')
Description: Copies source_folder
and all its contents to destination_folder
.
12. Create Multiple Directories:
FileMa.mkdirs('parent_folder/child_folder')
Description: Creates parent_folder
and child_folder
, including any necessary intermediate directories.
13. Remove Directories Recursively:
FileMa.rmdirs('folder_to_remove')
Description: Removes folder_to_remove
and all its contents.
14. Change the Current Directory:
FileMa.cd('path_to_directory')
Description: Changes the current working directory to path_to_directory
.
15. Print Directory Tree Structure:
FileMa.tree('path_to_directory')
Description: Prints the directory structure starting from path_to_directory
in a hierarchical format.
16. Print Current Working Directory:
FileMa.pwd()
Description: Prints the current working directory.
17. List Directory Contents:
FileMa.ls('path_to_directory')
Description: Lists the contents of path_to_directory
, indicating whether each item is a file or a directory.
18. List Directory Contents with Details:
FileMa.ls_l('path_to_directory')
Description: Lists the contents of path_to_directory
with detailed information, such as permissions, last modification time, and size.
19. Get Last Access Time of a File:
FileMa.istime('file_name')
Description: Prints the last access time of the file file_name
.
20. Get File Size:
FileMa.size('file_name')
Description: Prints the size of the file file_name
in bytes.
21. Print Environment Variables:
FileMa.get_info()
Description: Prints all environment variables and their values.
22. Print Executable Paths:
FileMa.get_path()
Description: Prints the paths where executables are searched for.
You can use these functions in your scripts to perform various file and directory operations effectively.