Skip to content
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

PR for File_search script #316

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions File_Search/file_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import pathlib
all_files_path = pathlib.Path('Place the folder path here under quotes')
file_paths = []

for file in all_files_path.rglob('*'):
if file.is_file():
file_paths.append(str(file))

formatted_output = '[\n' + ',\n'.join(f' "{path}"' for path in file_paths) + '\n]'
print(formatted_output)


file_extensions = []

for file in all_files_path.rglob('*'):
if file.is_file():
ext = file.suffix.lower()
if ext and ext not in file_extensions:
file_extensions.append(ext)


formattedd_output = '[\n' + ',\n'.join(f' "{ext}"' for ext in file_extensions) + '\n]'
print(formattedd_output)
31 changes: 31 additions & 0 deletions File_Search/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
File Path Finder and Unique Extension Lister:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you consider improving the all the heading?

Copy link
Author

Choose a reason for hiding this comment

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

Sure, I will improve it

This Python script searches a specified folder for all files, regardless of file type, within its directory and subdirectories. It outputs the paths of all files found and also lists all unique file extensions present in the folder. The script uses Python's pathlib module, which is cross-platform and simplifies working with file paths.

Features:
File Path Finder: The script scans a folder and lists the file paths of all files it finds within the specified directory and its subdirectories.
Unique File Extension Lister: The script identifies all unique file extensions present in the folder, displaying them in lowercase format.

Requirements: Python 3.x

Set the Folder Path:

Replace 'Place the folder path here under quotes' in the script with the path to the folder you want to scan:
all_files_path = pathlib.Path('path/to/your/folder')

Run the Script:

Save the script as file_finder.py (or another name of your choice).
Open your terminal or command prompt.
Navigate to the folder containing the script and run it with:
python file_finder.py

Output:
The script will output two lists:
The first list contains the paths of all files found within the specified folder and its subdirectories.
The second list contains all unique file extensions in the folder, displayed in lowercase.


Example output:

[ "path/to/folder/document.txt", "path/to/folder/image.jpg", "path/to/folder/subfolder/script.py"]
[ ".txt", ".jpg", ".py"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ Weight Converter | [Weight Converter](https://github.com/Wa
| Word to PDF | [Word to PDF](https://github.com/DhanushNehru/Python-Scripts/tree/master/Word%20to%20PDF%20converter) | A Python script to convert an MS Word file to a PDF file. |
| Youtube Downloader | [Youtube Downloader](https://github.com/DhanushNehru/Python-Scripts/tree/master/Youtube%20Downloader) | Downloads any video from [YouTube](https://youtube.com) in video or audio format!
| Youtube Playlist Info Scraper | [Youtube Playlist Info Scraper](https://github.com/DhanushNehru/Python-Scripts/tree/master/Youtube%20Playlist%20Info%20Scraper) | This python module retrieve information about a YouTube playlist in json format using playlist link.
| 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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please put the row in the correct order.

Copy link
Author

Choose a reason for hiding this comment

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

Sure, I will make the changes


## Gitpod

Expand Down