Skip to content

Error while renaming file references - Illegal characters in path #125

@HackXIt

Description

@HackXIt

Bug

During conversion, it fails to rename the reference of each image found.
It successfully creates & moves the images, but when renaming the references in markdown, the script fails for EVERY picture. (drawings as well)

Expectation

Renaming the file references should work, considering the files were moved properly.

Discussion

I renamed my username and the name of the Notebook for privacy purposes. The format stayed the same though, just used a different name for both.

Here is a sample output of the script: (it throws a lot of errors because of the amount of images)

VERBOSE: Moving image: C:\Users\user\AppData\Local\Temp\My-Notebook\2022-03-01-00-17-57-5426867\media\image7.png to C:\Users
\user\Desktop\tmp\My-Notebook\Allgemeines---Globale-Themen\Vorbereitung-Reihungstest\media\Chemie-image7.png
VERBOSE: Mutation of markdown: Rename image references to unique name. Find 'image7.png', Replacement: 'Chemie-image7.png'
Convert-OneNotePage : Error while renaming image file name references to 'Chemie-image7.png: Illegal characters in path.
At D:\#Git-Stash\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1:1387 char:257

+ ... onConfigs | Convert-OneNotePage -OneNoteConnection $OneNote -Config $ ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
  + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNotePage
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

VERBOSE: Moving image: C:\Users\user\AppData\Local\Temp\My-Notebook\2022-03-01-00-17-57-5426867\media\image70.png to C:\User
s\user\Desktop\tmp\My-Notebook\Allgemeines---Globale-Themen\Vorbereitung-Reihungstest\media\Chemie-image70.png
VERBOSE: Mutation of markdown: Rename image references to unique name. Find 'image70.png', Replacement: 'Chemie-image70.png'
Convert-OneNotePage : Error while renaming image file name references to 'Chemie-image70.png: Illegal characters in path.
At D:\#Git-Stash\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1:1387 char:257

+ ... onConfigs | Convert-OneNotePage -OneNoteConnection $OneNote -Config $ ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
  + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNotePage
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

VERBOSE: Moving image: C:\Users\user\AppData\Local\Temp\My-Notebook\2022-03-01-00-17-57-5426867\media\image71.png to C:\User
s\user\Desktop\tmp\My-Notebook\Allgemeines---Globale-Themen\Vorbereitung-Reihungstest\media\Chemie-image71.png
VERBOSE: Mutation of markdown: Rename image references to unique name. Find 'image71.png', Replacement: 'Chemie-image71.png'
Convert-OneNotePage : Error while renaming image file name references to 'Chemie-image71.png: Illegal characters in path.
At D:\#Git-Stash\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1:1387 char:257

+ ... onConfigs | Convert-OneNotePage -OneNoteConnection $OneNote -Config $ ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
  + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNotePage
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

VERBOSE: Moving image: C:\Users\user\AppData\Local\Temp\My-Notebook\2022-03-01-00-17-57-5426867\media\image72.png to C:\User
s\user\Desktop\tmp\My-Notebook\Allgemeines---Globale-Themen\Vorbereitung-Reihungstest\media\Chemie-image72.png
VERBOSE: Mutation of markdown: Rename image references to unique name. Find 'image72.png', Replacement: 'Chemie-image72.png'
Convert-OneNotePage : Error while renaming image file name references to 'Chemie-image72.png: Illegal characters in path.
At D:\#Git-Stash\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1:1387 char:257

+ ... onConfigs | Convert-OneNotePage -OneNoteConnection $OneNote -Config $ ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
  + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNotePage
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here is a sample from the converted markdown file, containing a reference, which can't be renamed:

Chemie

![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image1.png){width="0.8125in" height="1.2708333333333333in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image2.png){width="0.8611111111111112in" height="1.2569444444444444in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image3.png){width="0.9375in" height="0.7569444444444444in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image4.png){width="0.8819444444444444in" height="1.0416666666666667in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image5.png){width="0.9375in" height="1.0833333333333333in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image6.png){width="0.8611111111111112in" height="1.0in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image7.png){width="0.7986111111111112in" height="0.9930555555555556in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image8.png){width="0.8819444444444444in" height="1.0347222222222223in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image9.png){width="0.8194444444444444in" height="0.9513888888888888in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image10.png){width="0.875in" height="0.9930555555555556in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image11.png){width="1.0in" height="0.9513888888888888in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image12.png){width="0.875in" height="0.9583333333333334in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image13.png){width="0.8125in" height="0.8958333333333334in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image14.png){width="0.875in" height="0.9930555555555556in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image15.png){width="1.0347222222222223in" height="0.9027777777777778in"}

Saturday, 29 February 2020

14:49

![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image16.png){width="0.9027777777777778in" height="1.0833333333333333in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image17.png){width="0.875in" height="1.125in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image18.png){width="1.4583333333333333in" height="1.4722222222222223in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image19.png){width="0.7708333333333334in" height="1.0in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image20.png){width="0.8194444444444444in" height="1.1041666666666667in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image21.png){width="0.9236111111111112in" height="1.0416666666666667in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image22.png){width="0.8402777777777778in" height="0.9930555555555556in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image23.png){width="0.8958333333333334in" height="0.9166666666666666in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image24.png){width="0.8611111111111112in" height="0.8958333333333334in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image25.png){width="0.8958333333333334in" height="0.8819444444444444in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image26.png){width="0.8333333333333334in" height="0.8541666666666666in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image27.png){width="0.9236111111111112in" height="0.8958333333333334in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image28.png){width="0.8958333333333334in" height="0.8819444444444444in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image29.png){width="0.8194444444444444in" height="0.9722222222222222in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image30.png){width="0.9027777777777778in" height="0.9236111111111112in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image31.png){width="2.5in" height="1.8263888888888888in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image32.png){width="0.8125in" height="0.8333333333333334in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image33.png){width="1.6875in" height="1.6875in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image34.png){width="1.0833333333333333in" height="1.4930555555555556in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image35.png){width="1.4375in" height="1.625in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image36.png){width="5.25in" height="5.493055555555555in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image37.png){width="0.3958333333333333in" height="5.555555555555555in"}

<https://www.youtube.com/watch?v=J2KJRRH0E3Y>

 

<https://www.youtube.com/watch?v=f5-W87IGLFY>

 

simpleClub =\> Youtube

![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image38.png){width="1.2708333333333333in" height="1.4722222222222223in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image39.png){width="0.4444444444444444in" height="0.5763888888888888in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image40.png){width="0.4375in" height="0.5763888888888888in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image41.png){width="0.4236111111111111in" height="0.5486111111111112in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image42.png){width="1.0in" height="1.3680555555555556in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image43.png){width="0.3333333333333333in" height="0.4444444444444444in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image44.png){width="0.75in" height="0.7916666666666666in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image45.png){width="1.0208333333333333in" height="1.2916666666666667in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image46.png){width="0.7569444444444444in" height="1.1666666666666667in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image47.png){width="0.7430555555555556in" height="0.7916666666666666in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image48.png){width="0.8125in" height="1.25in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image49.png){width="0.7986111111111112in" height="1.3263888888888888in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image50.png){width="0.8541666666666666in" height="1.375in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image51.png){width="0.9236111111111112in" height="1.2083333333333333in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image52.png){width="1.0833333333333333in" height="1.875in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image53.png){width="0.9930555555555556in" height="0.7916666666666666in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image54.png){width="0.8958333333333334in" height="0.9513888888888888in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image55.png){width="0.8333333333333334in" height="1.0138888888888888in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image56.png){width="0.5486111111111112in" height="0.6666666666666666in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image57.png){width="0.8819444444444444in" height="0.9236111111111112in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image58.png){width="0.9236111111111112in" height="0.75in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image59.png){width="0.8958333333333334in" height="0.9722222222222222in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image60.png){width="0.8194444444444444in" height="0.9027777777777778in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image61.png){width="0.9722222222222222in" height="0.9166666666666666in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image62.png){width="0.8125in" height="0.9722222222222222in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image63.png){width="0.8611111111111112in" height="0.9375in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image64.png){width="0.7777777777777778in" height="0.9166666666666666in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image65.png){width="0.8402777777777778in" height="0.8402777777777778in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image66.png){width="0.875in" height="0.9236111111111112in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image67.png){width="0.8819444444444444in" height="1.1319444444444444in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image68.png){width="0.8958333333333334in" height="0.8819444444444444in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image69.png){width="0.8541666666666666in" height="1.0763888888888888in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image70.png){width="0.9166666666666666in" height="1.1944444444444444in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image71.png){width="0.8402777777777778in" height="1.0625in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image72.png){width="0.9027777777777778in" height="0.9930555555555556in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image73.png){width="1.2291666666666667in" height="1.0347222222222223in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image74.png){width="0.8611111111111112in" height="1.2986111111111112in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image75.png){width="3.5625in" height="1.875in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image76.png){width="0.875in" height="1.1736111111111112in"}

Erdöl

Einheiten

Bindungen

Säuren & Basen (PH-Wert)

Environment

Windows 11 Pro - 10.0.22000
I ran the script as administrator inside ISE and also ran OneNote (Office-Version) as Administrator

Aside from the images & drawings, the conversion works well.

Output of Configuration

For example:

$dryRun = 1
$notesdestpath = 'C:\Users\user\Desktop\tmp'
$targetNotebook = 'My Notebook'
$usedocx = 1
$keepdocx = 1
$docxNamingConvention = 2
$prefixFolders = 1
$mdFileNameAndFolderNameMaxLength = 32
$medialocation = 2
$conversion = 'markdown-simple_tables-multiline_tables-grid_tables+pipe_tables'
$headerTimestampEnabled = 1
$keepspaces = 1
$keepescape = 1
$newlineCharacter = 1
$exportPdf = 2

Output of $PSVersionTable

For example:

PS > $PSVersionTable
Name                           Value                                                                                        
----                           -----                                                                                        
PSVersion                      5.1.22000.282                                                                                
PSEdition                      Desktop                                                                                      
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                      
BuildVersion                   10.0.22000.282                                                                               
CLRVersion                     4.0.30319.42000                                                                              
WSManStackVersion              3.0                                                                                          
PSRemotingProtocolVersion      2.3                                                                                          
SerializationVersion           1.1.0.1 

Metadata

Metadata

Assignees

Labels

docsImprovements or additions to documentation

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions