@@ -4034,6 +4034,62 @@ package.preload["library.utils"] = package.preload["library.utils"] or function(
4034
4034
end
4035
4035
return mac_value
4036
4036
end
4037
+
4038
+ function utils .split_file_path (full_path )
4039
+ local path_name = finale .FCString ()
4040
+ local file_name = finale .FCString ()
4041
+ local file_path = finale .FCString (full_path )
4042
+
4043
+ if file_path :FindFirst (" /" ) >= 0 or (finenv .UI ():IsOnWindows () and file_path :FindFirst (" \\ " ) >= 0 ) then
4044
+ file_path :SplitToPathAndFile (path_name , file_name )
4045
+ else
4046
+ file_name .LuaString = full_path
4047
+ end
4048
+
4049
+ local extension = file_name .LuaString :match (" ^.+(%..+)$" )
4050
+ extension = extension or " "
4051
+ if # extension > 0 then
4052
+
4053
+ local truncate_pos = file_name .Length - finale .FCString (extension ).Length
4054
+ if truncate_pos > 0 then
4055
+ file_name :TruncateAt (truncate_pos )
4056
+ else
4057
+ extension = " "
4058
+ end
4059
+ end
4060
+ path_name :AssureEndingPathDelimiter ()
4061
+ return path_name .LuaString , file_name .LuaString , extension
4062
+ end
4063
+
4064
+ function utils .eachfile (directory_path , recursive )
4065
+ if finenv .MajorVersion <= 0 and finenv .MinorVersion < 68 then
4066
+ error (" utils.eachfile requires at least RGP Lua v0.68." , 2 )
4067
+ end
4068
+ recursive = recursive or false
4069
+ local lfs = require (' lfs' )
4070
+ local text = require (' luaosutils' ).text
4071
+ local fcstr = finale .FCString (directory_path )
4072
+ fcstr :AssureEndingPathDelimiter ()
4073
+ directory_path = fcstr .LuaString
4074
+ local lfs_directory_path = text .convert_encoding (directory_path , text .get_utf8_codepage (), text .get_default_codepage ())
4075
+ return coroutine.wrap (function ()
4076
+ for lfs_file in lfs .dir (lfs_directory_path ) do
4077
+ if lfs_file ~= " ." and lfs_file ~= " .." then
4078
+ local utf8_file = text .convert_encoding (lfs_file , text .get_default_codepage (), text .get_utf8_codepage ())
4079
+ local mode = lfs .attributes (lfs_directory_path .. lfs_file , " mode" )
4080
+ if mode == " directory" then
4081
+ if recursive then
4082
+ for subdir , subfile in utils .eachfile (directory_path .. utf8_file , recursive ) do
4083
+ coroutine.yield (subdir , subfile )
4084
+ end
4085
+ end
4086
+ elseif (mode == " file" or mode == " link" ) and lfs_file :sub (1 , 2 ) ~= " ._" then
4087
+ coroutine.yield (directory_path , utf8_file )
4088
+ end
4089
+ end
4090
+ end
4091
+ end )
4092
+ end
4037
4093
return utils
4038
4094
end
4039
4095
package.preload [" library.localization" ] = package.preload [" library.localization" ] or function ()
0 commit comments