Skip to content

Commit

Permalink
Organize Files, Rename Files, and Search Text Files (#342)
Browse files Browse the repository at this point in the history
* Added Pomodoro Timer

* Update README.md

* Update README.md

* Added FileOrganizer,FileRenamer and FileTextSearch
  • Loading branch information
max-lopzzz authored Oct 18, 2024
1 parent 0671816 commit 88ee0ad
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 0 deletions.
26 changes: 26 additions & 0 deletions FileOrganizer/FileOrganizer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
import shutil

# Prompt the user for the directory path to organize files
path = input("Enter path: ")

# List all files in the specified directory
files = os.listdir(path)

# Iterate through each file in the directory
for file in files:
# Split the filename and extension
filename, extension = os.path.splitext(file)

# Remove the leading dot from the extension for folder naming
extension = extension[1:]

# Check if a directory for the file extension already exists
if os.path.exists(path + '/' + extension):
# Move the file to the corresponding extension folder
shutil.move(path + '/' + file, path + '/' + extension + '/' + file)
else:
# If the directory does not exist, create it
os.makedirs(path + '/' + extension)
# Move the file to the newly created extension folder
shutil.move(path + '/' + file, path + '/' + extension + '/' + file)
22 changes: 22 additions & 0 deletions FileOrganizer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# File Organizer Script
## Description
The `FileOrganizer.py` script is a simple utility for organizing files in a specified directory. It automatically sorts files into subdirectories based on their file extensions, making it easier to manage and locate files.
## Features
- *Automatic Organization:* Files are moved into subfolders named after their extensions (e.g., all `.jpg` files go into a folder named `jpg`).
- *Dynamic Folder Creation:* If a folder for a specific file type doesn't exist, it will be created automatically.
## Usage
1. Ensure you have Python installed on your machine.
2. Download the FileOrganizer.py script.
3. Open a terminal or command prompt and navigate to the directory where the script is located.
4. Run the script using the following command:
python FileOrganizer.py
5. When prompted, enter the path of the directory you want to organize.
Enter path: /path/to/your/directory
6. The script will process the files in the specified directory and create folders for each file type, moving the corresponding files into their respective folders.
## Requirements
- Python 3.x
- Basic understanding of file paths in your operating system.
## License
This script is open-source and free to use. Feel free to modify and distribute as needed.
## Contributing
If you'd like to contribute to this project, please open an issue or submit a pull request with your proposed changes or enhancements.
31 changes: 31 additions & 0 deletions FileRenamer/File_Renamer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
import re

# Prompt the user for the directory path where files need to be renamed
directory = input("Enter path: ")

# Provide instructions on how to use regex for searching specific files
print("To look for specific files, enter what you know, using .* for any characters you don't know.")
print("For example: IMG.* will filter files that start with IMG")

# Get the regex pattern to match files and the new base name for renaming
pattern = input("Enter pattern: ")
new_name = input("Enter the new name: ")

def rename_files(directory, pattern, new_name):
# List all files in the specified directory
files = os.listdir(directory)
counter = 0 # Initialize a counter for unique naming

# Iterate over each file in the directory
for file in files:
# Check if the file matches the given pattern
if re.match(pattern, file):
# Get the file extension
filetype = file.split('.')[-1]
# Rename the file with the new base name and counter
os.rename(directory + '/' + file, directory + '/' + new_name + str(counter) + '.' + filetype)
counter += 1 # Increment the counter for the next file

# Call the function to rename files
rename_files(directory, pattern, new_name)
27 changes: 27 additions & 0 deletions FileRenamer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# File Renamer Script
## Description
The `FileRenamer.py` script is a utility designed to rename multiple files in a specified directory based on a given regex pattern. This script helps users quickly standardize file names, making file management easier.
## Features
- *Batch Renaming:* Rename multiple files that match a specified regex pattern.
- *Custom Naming:* Users can provide a new base name for the renamed files, with a counter appended to ensure unique names.
## Usage
1. Ensure you have Python installed on your machine.
2. Download the `FileRenamer.py` script.
3. Open a terminal or command prompt and navigate to the directory where the script is located.
4. Run the script using the following command:
python `FileRenamer.py`
5. When prompted, enter the path of the directory containing the files you want to rename.
Enter path: /path/to/your/directory
6. Enter the regex pattern for the files you want to rename. For example:
Enter pattern: IMG.*
7. Enter the new base name for the renamed files.
Enter the new name: NewImageName
8. The script will rename all matching files in the specified directory according to the new name format.
## Requirements
- Python 3.x
- Basic understanding of file paths in your operating system.
- Familiarity with regex patterns for filtering files.
## License
This script is open-source and free to use. Feel free to modify and distribute as needed.
## Contributing
If you'd like to contribute to this project, please open an issue or submit a pull request with your proposed changes or enhancements.
55 changes: 55 additions & 0 deletions FileTextSearch/FileTextSearch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import os
import uuid

# Initialize a list to store files containing the keyword
contains = []

# Generate a unique identifier for this search session (not currently used)
id_ = uuid.uuid4()

# List of file extensions to search within
extensions = [".txt", ".docx", ".pdf"]

def change_direct():
# Prompt the user to enter the directory path
path = input("Enter path: ")
# Prompt the user to enter the keyword or phrase to search for
keyword = input("Keyword/Phrase: ")
# Start searching the specified folder
search_folder(path, keyword)

def search_folder(path, keyword):
global contains # Declare the global variable to store found files
# Check if the given path is a directory
if os.path.isdir(path):
# List all files and directories in the specified path
files = os.listdir(path)
# Iterate over each file in the directory
for file in files:
# Construct the full path to the file or directory
full_path = os.path.join(path, file)

# If the current path is a directory, recursively search inside it
if os.path.isdir(full_path):
search_folder(full_path, keyword)
else:
# Get the file extension and convert it to lowercase
filetype = os.path.splitext(file)[-1].lower()
# Check if the file type is in the allowed extensions
if filetype in extensions:
try:
# Open the file and read its content
with open(full_path, 'r', encoding='utf-8', errors='ignore') as file_:
# Check if the keyword is found in the file content
if keyword in file_.read():
contains.append(file) # Add the file to the list of found files
print(keyword, "found in", file) # Print the result
except Exception as e:
# Print any errors encountered while reading the file
print(f"Error reading {full_path}: {e}")
else:
# Print an error message if the provided path is not a directory
print(f"{path} is not a directory.")

# Start the process by calling the change_direct function
change_direct()
26 changes: 26 additions & 0 deletions FileTextSearch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# File Text Search Script
## Description
The `FileTextSearch.py` script is a utility designed to search for a specific keyword or phrase within text-based files located in a specified directory. The script searches through files with the following extensions: `.txt`, `.docx`, and `.pdf`. It can recursively search through subdirectories, making it easier to locate documents containing the desired information.
## Features
- Recursive Searching: The script can search within specified subdirectories.
- Keyword Matching: Users can input a keyword or phrase to find within the text files.
- Supported Formats: The script can read `.txt`, `.docx`, and `.pdf` file formats.
## Usage
1. Ensure you have Python installed on your machine.
2. Download the `FileTextSearch.py` script.
3. Open a terminal or command prompt and navigate to the directory where the script is located.
4. Run the script using the following command:
python FileTextSearch.py
5. When prompted, enter the path of the directory you want to search.
Enter path: /path/to/your/directory
6. Enter the keyword or phrase you want to search for in the files.
Keyword/Phrase: your_keyword
7. The script will search through the specified directory and print out the names of any files where the keyword is found.
## Requirements
- Python 3.x
- Basic understanding of file paths in your operating system.
- The script will read text-based files, so ensure the files are not encrypted or password protected.
## License
This script is open-source and free to use. Feel free to modify and distribute as needed.
## Contributing
If you'd like to contribute to this project, please open an issue or submit a pull request with your proposed changes or enhancements.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ More information on contributing and the general code of conduct for discussion
| File Encryption Decryption | [File Encryption Decryption](https://github.com/DhanushNehru/Python-Scripts/tree/master/File%20Encryption%20Decryption) | Encrypts and Decrypts files using AES Algorithms for Security purposes. |
| File Search | [File_search](https://github.com/debojit11/Python-Scripts/tree/master/File_Search) | A python script that searches a specified folder for all files, regardless of file type, within its directory and subdirectories.
| Font Art | [Font Art](https://github.com/DhanushNehru/Python-Scripts/tree/master/Font%20Art) | Displays a font art using Python. |
| File Organizer | [FileOrganizer](https://github.com/DhanushNehru/Python-Scripts/tree/master/FileOrganizer) | Organizes files into different folders according to their file type
| File Renamer | [FileRenamer](https://github.com/DhanushNehru/Python-Scripts/tree/master/FileRenamer) | Bulk renames files with the same start/end
| File Text Search | [FileTextSearch](https://github.com/DhanushNehru/Python-Scripts/tree/master/FileTextSearch) | Searches for a keyword/phrase accross different files
| Freelance Helper Program | [freelance-helper](https://github.com/DhanushNehru/Python-Scripts/tree/master/freelance-help-program) | Takes an Excel file with working hours and calculates the payment. |
| Get Hexcodes From Websites | [Get Hexcodes From Websites](https://github.com/DhanushNehru/Python-Scripts/tree/master/Get%20Hexcodes%20From%20Websites) | Generates a Python list containing Hexcodes from a website. |
| Hand_Volume | [Hand_Volume](https://github.com/DhanushNehru/Python-Scripts/tree/master/Hand%20Volume) | Detects and tracks hand movements to control volume. |
Expand Down

0 comments on commit 88ee0ad

Please sign in to comment.