* Error when renaming file with accented characters

Writing and using plugins for Version 5 and above.
avatar
JoopvB
Superstar
Posts: 271
Joined: 02 May 2015 14:32
Family Historian: V7

Re: Error when renaming file with accented characters

Post by JoopvB » 01 Mar 2021 18:08

I'll make sure that mapping to ? are substituted by ~.

Thanks mike.

User avatar
ColeValleyGirl
Megastar
Posts: 2720
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Error when renaming file with accented characters

Post by ColeValleyGirl » 02 Mar 2021 12:48

JoopvB,

try this snippet to rename a file -- you'll need to modify the file path and names, as it's only a proof of concept right now. You'll also need to check that the source file (first one specified) exists before running the code. Note: MoveFile renames the file if source and destination folder are the same.

Code: Select all

require "luacom"
fso    = luacom.CreateObject("Scripting.FileSystemObject")
result = fso:MoveFile("C:\\ололоо я водитель.txt","C:\\о보라보라 я водитель н보라.txt")
If it works for you, I'll put creating a proper code snippet together on my todo list -- we will need to check that it works in emulated environments as well..

avatar
JoopvB
Superstar
Posts: 271
Joined: 02 May 2015 14:32
Family Historian: V7

Re: Error when renaming file with accented characters

Post by JoopvB » 02 Mar 2021 16:36

Helen,

Interesting approach and as far as I can see it works. I Tested it with:

-- From simple to complex
local sTitle = 'Test - Sydney, Australië 2014-01-10 - Joop äüè - о보라보라 я водитель н보라'
local oldFileName = 'D:\\OneDrive\\Documents\\Genealogie\\BR\\Identificatie\\PP\\Test - Sydney 2014-01-10 - Joop.jpg'
local path,name,ext = splitFilename(oldFileName)
local newFileName = path .. sTitle .. '.' .. ext
local bCheck = fileExists(oldFileName) --> true
local bFound = fso:FileExists(oldFileName) --> true
if bFound then
local result = fso:MoveFile(oldFileName,newFileName)
end

-- And back from complex to simple
sTitle = 'Test - Sydney 2014-01-10 - Joop no specials'
oldFileName = 'D:\\OneDrive\\Documents\\Genealogie\\BR\\Identificatie\\PP\\Test - Sydney, Australië 2014-01-10 - Joop äüè - о보라보라 я водитель н보라.jpg'
path,name,ext = splitFilename(oldFileName)
newFileName = path .. sTitle .. '.' .. ext
bCheck = fileExists(oldFileName) --> false
bFound = fso:FileExists(oldFileName) --> true
if bFound then
local result = fso:MoveFile(oldFileName,newFileName)
end

Notice that fileExists (uses io.open) returns false when reverting the filename back from complex to simple. fso.fileExists however returns true resulting in a correct renaming.

Maybe more extensive testing is needed, but I'm confident that this is what we've been looking for.

Thanks!

User avatar
ColeValleyGirl
Megastar
Posts: 2720
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Error when renaming file with accented characters

Post by ColeValleyGirl » 02 Mar 2021 17:05

Glad to (fingers crossed) have cracked it. I suggest you don't wait for me to generate a code snippet, as I want to think about what else the same technique can address in the file system with utf8/utf16 characters.

avatar
JoopvB
Superstar
Posts: 271
Joined: 02 May 2015 14:32
Family Historian: V7

Re: Error when renaming file with accented characters

Post by JoopvB » 02 Mar 2021 17:27

Helen, I'm glad that you found this solution and I also think it seems promising for a broader use than only renaming.

I'll update the plugin to incorporate this approach (no snippet needed. :)).

Thanks!

Post Reply