Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: fishercoder1534/Leetcode
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: df7a9cb
Choose a base ref
...
head repository: lmgyuan/Leetcode
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3f86ca9
Choose a head ref
  • 1 commit
  • 5 files changed
  • 1 contributor

Commits on Jan 31, 2025

  1. Copy the full SHA
    3f86ca9 View commit details
48 changes: 48 additions & 0 deletions src/main/java/com/fishercoder/file_count/counter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os

def count_lines_in_file(file_path):
"""Counts the number of lines in a given file."""
with open(file_path, 'r', encoding='utf-8') as file:
return sum(1 for _ in file)

def read_file_content(file_path):
"""Reads and returns the content of a file."""
with open(file_path, 'r', encoding='utf-8') as file:
return file.read()

def scan_java_files(directory):
"""Scans Java files in a directory and filters those with over 100 lines."""
java_files_over_100_lines = []

for root, _, files in os.walk(directory):
for file in files:
if file.endswith(".java"):
file_path = os.path.join(root, file)
line_count = count_lines_in_file(file_path)
if line_count > 100:
content = read_file_content(file_path)
java_files_over_100_lines.append((file, line_count, content))

return java_files_over_100_lines

if __name__ == "__main__":
directory = "../solutions/fourththousand"
file_name = directory.split("/")[-1]
result = scan_java_files(directory)

if result:
print("Java files with more than 100 lines:")
for file, lines, _ in result:
print(f"{file}: {lines} lines")
with open(f"./{file_name}.txt", "w", encoding='utf-8') as f:
f.write(f"Total files count: {len(result)}\n")
for file, lines, content in result:
f.write(f"{'='*50}\n")
f.write(f"File: {file}\n")
f.write(f"Line count: {lines}\n")
f.write(f"{'='*50}\n")
f.write("Content:\n")
f.write(content)
f.write("\n\n")
else:
print("No Java files with more than 100 lines found.")
Loading