Hi all,
I'm working now on a skin and as a part of it I'd like to copy a jpg image from a folder into another. For this I've created a small lua script, but it works just for txt files (if I copy a txt file, it is all right, but a jpg isn't copied entirely: the copy of a 20 KB image has 300 B and can't be opened).
I'm asking a lua expert to help me to can copy the image. So, here's my code:
function CopyImg(src, dest)
local mp_log = io.open(src, "r")
local output = io.open(dest, "w")
output:write(mp_log:read("*all"))
output:close()
mp_log:close()
end
function Initialize()
CopyImg("d:/1.jpg", "e:/1.jpg")
end
I think it's obvious that I want to copy the d:/1.jpg file to e:/1.jpg.
Thanks in advance.
function Initialize()
end
function Update()
end
function FileCopy()
SKIN:Bang('!CommandMeasure', 'MeasureRun', 'Run')
end
Not too hard.
You can almost certainly "pass" the file names from the skin to the Lua as well, then use a SKIN:Bang('!SetOption', ..) to set the "Parameter" option on the RunCommandPlugin and then fire it, but I caution that it quickly gets complicated dealing with the reserved "\" character in folder paths in Windows, and proper "quoting" back and forth to deal with spaces in the path names. If you need to change it dynamically, it might be easier in the long run to use !SetVariable directly in the skin to change the file paths and names, then just use the Lua to simply "fire" the RunCommand measure at whatever point in your Lua code is appropriate.
function Initialize()
end
function Update()
end
function FileCopy()
SKIN:Bang('!CommandMeasure', 'MeasureRun', 'Run')
end
Before clicking:
1.jpg
After clicking:
2.jpg
test.gif
The DynamicVariables=1 on the meter showing the "new / copied" image file is important. When the skin is first loaded, that image does not exist, and the meter returns a "file not found" error. It won't try again (to not just hammer the log with errors) unless it is dynamically evaluating that #Variable#" on each update.
Really you don't need the Lua, you could directly !CommandMeasure the RunCommand plugin to fire it. This was mostly just an example of how you could do a "file copy" that might be done in Lua, without getting the cmd.exe popup...
You do not have the required permissions to view the files attached to this post.