-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_directory_structure_to_file.ps1
43 lines (34 loc) · 2.58 KB
/
list_directory_structure_to_file.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Define the base directory and output file
$baseDir = "C:\Users\nicol\Nextcloud\Documents\GIT_Projects\SnipSet"
$outputFile = "directory_structure.txt"
$maxDepth = 1 # Set the maximum depth you want to display
# Function to get directory structure up to a specified depth
function Get-DirectoryStructure {
param (
[string]$path,
[int]$currentDepth,
[int]$maxDepth
)
$items = Get-ChildItem -Path $path
$output = @()
foreach ($item in $items) {
$indent = "│ " * ($currentDepth - 1)
if ($currentDepth - 1 -eq 0) {
$output += $indent + $item.Name
} else {
$output += $indent + "├───" + $item.Name
}
if ($item.PSIsContainer -and $currentDepth -lt $maxDepth) {
$subItems = Get-DirectoryStructure -path $item.FullName -currentDepth ($currentDepth + 1) -maxDepth $maxDepth
$output += $subItems
}
}
return $output
}
# Initialize output with the base directory
$output = @($baseDir)
# Get the directory structure
$output += Get-DirectoryStructure -path $baseDir -currentDepth 1 -maxDepth $maxDepth
# Write the output to a file
$output | Out-File -FilePath $outputFile
Write-Output "Directory structure saved to $outputFile"