Skip to content

Commit

Permalink
🐛 fix(theBrain): Exclude backup folder from file search
Browse files Browse the repository at this point in the history
In this commit, we address the issue where our PowerShell scripts were
incorrectly searching for both original and backup files. The previous
implementation inadvertently included the backup folder in the search
results.

To resolve this, we now use the following way to limit the path(s) to
search:

```powershell
$PathToSearch = Get-ChildItem -Directory -Path $BrainFolder -Exclude ‘Backup’
```

This ensures that only original files are considered, excluding any
files within the 'Backup' folder.

Fixes #16
  • Loading branch information
chriskyfung committed Jan 27, 2024
1 parent 16b9048 commit a8f5a4d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion theBrain/Get-TheBrainNotesLinks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

# Look up markdown links within the Notes.md files that locate under the Brain data folder
$BrainFolder = . "$PSScriptRoot\Get-TheBrainDataDirectory.ps1"
$MatchInfo = Get-ChildItem -Path $BrainFolder -Filter 'Notes.md' -Recurse | Select-String -Pattern '(?!-\{)\[([^\]]+)\]\((https?://[^()]+)\)(?!}-)' -AllMatches
$PathToSearch = Get-ChildItem -Directory -Path $BrainFolder -Exclude 'Backup'
$MatchInfo = Get-ChildItem -Path $PathToSearch -Filter 'Notes.md' -Recurse | Select-String -Pattern '(?!-\{)\[([^\]]+)\]\((https?://[^()]+)\)(?!}-)' -AllMatches
$LinkList = $MatchInfo | Select-Object *, @{Name = "MarkdownLink"; Expression = { $_.Matches.Value } }, @{Name = "LinkText"; Expression = { $_.Matches.Groups[1].Value } } , @{Name = "URL"; Expression = { $_.Matches.Groups[2].Value } }

# Output the results in DataTable view
Expand Down
3 changes: 2 additions & 1 deletion theBrain/Open-TheBrainNodeFolder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

# Look up the Notes.md files that locate under the Brain data folder and contain the YouTube thumbnail URLs.
$BrainFolder = . "$PSScriptRoot\Get-TheBrainDataDirectory.ps1"
$Folder = Get-ChildItem -Path $BrainFolder -Filter $NodeId -Recurse
$PathToSearch = Get-ChildItem -Directory -Path $BrainFolder -Exclude 'Backup'
$Folder = Get-ChildItem -Path $PathToSearch -Directory -Filter $NodeId -Recurse

explorer.exe $Folder.FullName
3 changes: 2 additions & 1 deletion theBrain/Resize-TheBrainNotesYouTubeThumbnail.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ $ErrorActionPreference = "Stop"

# Look up the Notes.md files that locate under the Brain data folder and contain the YouTube thumbnail URLs.
$BrainFolder = . "$PSScriptRoot\Get-TheBrainDataDirectory.ps1"
$SubFolders = Get-ChildItem -Directory -Path $BrainFolder -Exclude 'Backup'
$BackupFolder = Join-Path $BrainFolder 'Backup'

$Filename = 'Notes.md'
$FilenameWithoutExtension = [System.IO.Path]::GetFileNameWithoutExtension($Filename)
$FileExtension = [System.IO.Path]::GetExtension($Filename)

Write-Host 'Scanning YouTube thumbnail URLs in Brain Notes...'
$MatchInfo = Get-ChildItem -Path $BrainFolder -Exclude $BackupFolder -Filter $Filename -Recurse | Select-String '\/(hq|maxres)default.jpg\)' -List
$MatchInfo = Get-ChildItem -Path $SubFolders -Filter $Filename -Recurse | Select-String '\/(hq|maxres)default.jpg\)' -List

# For each matching result
Write-Information 'Backing up and modifying Brain Notes...'
Expand Down

0 comments on commit a8f5a4d

Please sign in to comment.