Skip to content

Commit 734eabe

Browse files
authored
PR for File_search script (DhanushNehru#316)
* Create file_search.py * Create readme.md * Update file_search.py * Update readme.md * Update readme.md * Update README.md * improved the heading in readme.md * placed the name , link and description in correct row
1 parent 65c5a3a commit 734eabe

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

File_Search/file_search.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import pathlib
2+
all_files_path = pathlib.Path('Place the folder path here under quotes')
3+
file_paths = []
4+
5+
for file in all_files_path.rglob('*'):
6+
if file.is_file():
7+
file_paths.append(str(file))
8+
9+
formatted_output = '[\n' + ',\n'.join(f' "{path}"' for path in file_paths) + '\n]'
10+
print(formatted_output)
11+
12+
13+
file_extensions = []
14+
15+
for file in all_files_path.rglob('*'):
16+
if file.is_file():
17+
ext = file.suffix.lower()
18+
if ext and ext not in file_extensions:
19+
file_extensions.append(ext)
20+
21+
22+
formattedd_output = '[\n' + ',\n'.join(f' "{ext}"' for ext in file_extensions) + '\n]'
23+
print(formattedd_output)

File_Search/readme.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Automated File Explorer:
2+
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.
3+
4+
Features:
5+
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.
6+
Unique File Extension Lister: The script identifies all unique file extensions present in the folder, displaying them in lowercase format.
7+
8+
Requirements: Python 3.x
9+
10+
Set the Folder Path:
11+
12+
Replace 'Place the folder path here under quotes' in the script with the path to the folder you want to scan:
13+
all_files_path = pathlib.Path('path/to/your/folder')
14+
15+
Run the Script:
16+
17+
Save the script as file_finder.py (or another name of your choice).
18+
Open your terminal or command prompt.
19+
Navigate to the folder containing the script and run it with:
20+
python file_finder.py
21+
22+
Output:
23+
The script will output two lists:
24+
The first list contains the paths of all files found within the specified folder and its subdirectories.
25+
The second list contains all unique file extensions in the folder, displayed in lowercase.
26+
27+
28+
Example output:
29+
30+
[ "path/to/folder/document.txt", "path/to/folder/image.jpg", "path/to/folder/subfolder/script.py"]
31+
[ ".txt", ".jpg", ".py"]

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ More information on contributing and the general code of conduct for discussion
6363
| Face Reaction | [Face Reaction](https://github.com/DhanushNehru/Python-Scripts/tree/master/Face%20Reaction) | A script which attempts to detect facial expressions. |
6464
| Fake Profiles | [Fake Profiles](https://github.com/DhanushNehru/Python-Scripts/tree/master/Fake%20Profile) | Creates fake profiles. |
6565
| 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. |
66+
| 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.
6667
| Font Art | [Font Art](https://github.com/DhanushNehru/Python-Scripts/tree/master/Font%20Art) | Displays a font art using Python. |
6768
| 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. |
6869
| 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. |

0 commit comments

Comments
 (0)