Closed johnkyle4 closed 3 years ago
hi @johnkyle4 could your try:
return (($newName.Replace(" ", "_").Replace(".", "")))
to replace the dots in the name as well, as they clutter a bit.return ($newName.Replace(" ", "_").Substring(0,$(@{$true=130;$false=$newName.length}[$newName.length -gt 130])))
to cap all file and folder names to 130 characters (number is an example, maybe you could 'up' this, not exceeding 248 NTFS limit).Hope you manage to make it work.
Thank you so much! Tried each of your suggestions, and this one is working:
if above does not work you can change line 10 to:
return ($newName.Replace(" ", "_").Substring(0,$(@{$true=130;$false=$newName.length}[$newName.length -gt 130])))
to cap all file and folder names to 130 characters (number is an example, maybe you could 'up' this, not exceeding 248 NTFS limit).
Now it's drilling through my thousands of notes successfully! I will go get that cup of coffee now :)
BTW, as it's running now there are very occasional errors, for example when the title has one of these characters: [
]
Error while renaming image file path references for file 'Random shit [tbo]': A parameter cannot be found that matches parameter name 'Raw'.
These are so rare I can likely sort them out myself.
I vastly appreciate your help and hard work! This script is a godsend.
@johnkyle4, Great to hear you are making good progress.
The function used to get all illegal characters ([IO.Path]::GetInvalidFileNameChars()
) is not flawless but if you feel the [ ] character errors should be prevented please change line 10 from:
return ($newName.Replace(" ", "_").Substring(0,$(@{$true=130;$false=$newName.length}[$newName.length -gt 130])))
to:
return (((($newName -replace "\s", "_") -replace "\[", "(") -replace "\]", ")").Substring(0,$(@{$true=130;$false=$newName.length}[$newName.length -gt 130])))
This will additionally rename the square brackets to round ones.
First of all, thank you for this miraculous script. I am so close to realizing my dream of moving out of OneNote to Markdown.
I'm almost there. My prior errors were caused by not running OneNote in administrator mode, and not having MS Word installed. Now it's working, except...
Many of my OneNote pages have no title, just content. OneNote substitutes note content for blank titles.
I'm getting errors in this script when my titles are blank and the substituted content is over 183 characters.
I am wondering if there is a way to modify your script to handle this, to do something like truncating the title? I have thousands of notes and I can't do it manually.
I've looked at some Onetastic macros but I can't find one that works to add a title to all pages.
Thank you for your help and for creating this script 🙏