Skip to content

Commit

Permalink
Fix: Add normalization of the notes destination path to have no trail…
Browse files Browse the repository at this point in the history
…ing slashes or backslashes

When a user enters one or more trailing front slashes in the notes destination path, the script might error out on some Powershell versions due to invalid paths.

This fix adds normalization of the notes destination path to have no trailing slashes or backslashes. It does not change any functionality, but ensures that the script does not error out due to invalid paths.
  • Loading branch information
leojonathanoh committed Jul 30, 2021
1 parent 93d0432 commit 525e8e1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ConvertOneNote2MarkDown-v2.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Function ProcessSections ($group, $FilePath) {
else {
$mediaPath = $NotebookFilePath.Replace('\', '/') # Normalize markdown media paths to use front slashes, i.e. '/'
}
$mediaPath = ($mediaPath.Substring(0, 1).tolower() + $mediaPath.Substring(1)).Replace('\', '/') # Normalize markdown media paths to use front slashes, i.e. '/'
$mediaPath = $mediaPath.Substring(0, 1).tolower() + $mediaPath.Substring(1) # Normalize markdown media paths to use a lowercased drive letter

# in case multiple pages with the same name exist in a section, postfix the filename. Run after pages
if ([System.IO.File]::Exists("$($fullfilepathwithoutextension).md")) {
Expand Down Expand Up @@ -386,7 +386,7 @@ try {
if (! (Test-Path -Path $notesdestpath -PathType Container -ErrorAction SilentlyContinue) ) {
throw "Notes root path does not exist: $notesdestpath"
}
$notesdestpath = $notesdestpath.Trim('\')
$notesdestpath = $notesdestpath.Trim('/').Trim('\') # Normalize notes paths to have no trailing slash or backslashes

if ($prefixFolders -eq 2) {
$prefixFolders = 2
Expand Down

0 comments on commit 525e8e1

Please sign in to comment.