Magic Lantern Forum

Developing Magic Lantern => Scripting Corner => Topic started by: ShittyWebsite on December 21, 2021, 01:23:16 PM

Title: Lua script to change file extension?
Post by: ShittyWebsite on December 21, 2021, 01:23:16 PM
Hello, so, i have a little problem, a pin on my CF slot is gone, i was wondering, if i could copy files via USB (but i'm guessing it wont show any MLV) is i possible configure a lua script to bypass USB files and change all mlv to .mov? i would copy the files then change back to .mlv

Fixing the CF is not gonna be possible, no new parts where i live, i managed to run CF using a copper wire but removing the CF and the wire from the camera too many times files would be a problem
Title: Re: Lua script to change file extension?
Post by: Walter Schulz on December 21, 2021, 02:26:11 PM
Can be done by LUA but I recommend replacing the CF-slot. It is available from various sites beginning at around 35 USD (without shipping).
There is are several replacement tutorials online including one from IFixedIt.
Title: Re: Lua script to change file extension?
Post by: ShittyWebsite on December 22, 2021, 01:16:46 AM
I'm from brazil, i'm not sure if i can do it on my own, seems.. complicated..



I could not find a starting point in lua
Title: Re: Lua script to change file extension?
Post by: kitor on December 22, 2021, 10:40:18 AM
Walter wrote about replacing whole PCB with CF slot, not the slot itself.

As for LUA, I never used it, but from what I see it uses `FIO_RenameFile` and `FIO_MoveFile`

Code: [Select]
/***
 Renames/moves a file on the card (or between cards).
 @tparam string filename
 @treturn bool success
 @function rename
 */
static int luaCB_dryos_rename(lua_State * L)
{
    LUA_PARAM_STRING(src, 1);
    LUA_PARAM_STRING(dst, 2);
    int err = FIO_RenameFile(src, dst);
    if (err)
    {
        err = FIO_MoveFile(src, dst);
    }
    lua_pushboolean(L, err == 0);
    return 1;
}

I guess `dryos_rename` is the function then? Of course needs to be combined with other functions (`dryos_directory` `directory_files` ? ) to iterate over files first and find files to rename.
Title: Re: Lua script to change file extension?
Post by: ShittyWebsite on December 22, 2021, 11:41:44 AM
Ooh i see, thank you, what i'm doing rn, i go to file manager and copy from card A to B card, so everything goes to the SD

 Nice code, i will try
Title: Re: Lua script to change file extension?
Post by: kitor on December 22, 2021, 11:54:03 AM
Code from above is C source from lua.mo, not the actual Lua script code. As stated before, I never used lua.mo nor written in Lua. Thus this part you need to solve yourself.
I only wrote that it should be possible with what I was able to find in module code.