-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2ad295
commit 1f8574f
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import os | ||
from pathlib import Path | ||
import sys | ||
|
||
def create_directory_tree(root_path, output_file, indent="", is_last=True): | ||
root = Path(root_path) | ||
|
||
output_file.write(f"{indent}{'└── ' if is_last else '├── '}{root.name}/\n") | ||
|
||
indent += " " if is_last else "│ " | ||
|
||
entries = list(root.iterdir()) | ||
entries.sort(key=lambda x: (not x.is_dir(), x.name.lower())) | ||
|
||
file_extensions = set() | ||
|
||
for i, entry in enumerate(entries): | ||
if entry.is_dir(): | ||
create_directory_tree(entry, output_file, indent, i == len(entries) - 1) | ||
else: | ||
file_extensions.add(entry.suffix.lower() if entry.suffix else "(no extension)") | ||
|
||
for i, ext in enumerate(sorted(file_extensions)): | ||
is_last_ext = i == len(file_extensions) - 1 | ||
output_file.write(f"{indent}{'└── ' if is_last_ext else '├── '}*{ext}\n") | ||
|
||
def main(): | ||
if len(sys.argv) > 1: | ||
root_directory = sys.argv[1] | ||
else: | ||
root_directory = "." | ||
|
||
output_filename = "directory_tree.txt" | ||
|
||
with open(output_filename, 'w', encoding='utf-8') as output_file: | ||
create_directory_tree(root_directory, output_file) | ||
|
||
print(f"Directory tree has been saved to {output_filename}") | ||
input("Press Enter to exit...") | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
def find_dta_files(root_path, output_file): | ||
root = Path(root_path).resolve() # Get the absolute path | ||
|
||
with open(output_file, 'w') as f: | ||
for path in root.rglob('*.dta'): | ||
relative_path = path.relative_to(root) | ||
f.write(f"{relative_path}\n") | ||
|
||
# Usage | ||
root_directory = "." # Current directory | ||
output_file = "dta_files_list.txt" # Name of the output file | ||
|
||
find_dta_files(root_directory, output_file) | ||
print(f"List of .dta files has been written to {output_file}") |