Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit abdf05b

Browse files
Merge pull request #3 from Jackeastern/patch-1
Add Find File To Python Snippet
2 parents 8b6f872 + 3185159 commit abdf05b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

‎public/data/python.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,32 @@
9494
],
9595
"tags": ["python", "file", "write", "utility"],
9696
"author": "technoph1le"
97+
},
98+
{
99+
"title": "Find Files",
100+
"description": "Finds all files of the specified type within a given directory.",
101+
"code": [
102+
"import os",
103+
"",
104+
"def find_files(directory, file_type):",
105+
" file_type = file_type.lower() # Convert file_type to lowercase",
106+
" found_files = []",
107+
"",
108+
" for root, _, files in os.walk(directory):",
109+
" for file in files:",
110+
" file_ext = os.path.splitext(file)[1].lower()",
111+
" if file_ext == file_type:",
112+
" full_path = os.path.join(root, file)",
113+
" found_files.append(full_path)",
114+
"",
115+
" return found_files",
116+
"",
117+
"# Example Usage:",
118+
"pdf_files = find_files('/path/to/your/directory', '.pdf')",
119+
"print(pdf_files)"
120+
],
121+
"tags": ["python", "os", "filesystem", "file_search"],
122+
"author": "Jackeastern"
97123
}
98124
]
99125
},

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /