I'll make sure that mapping to ? are substituted by ~.
Thanks mike.
* Error when renaming file with accented characters
- 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
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.
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..
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")
Re: Error when renaming file with accented characters
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!
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!
- 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
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.
Re: Error when renaming file with accented characters
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!
I'll update the plugin to incorporate this approach (no snippet needed.

Thanks!