使用 Lua 脚本在 VLC 中重命名当前文件

我正在使用这个脚本来重命名 VLC 中的文件:https://github.com/surrim/vlc-delete/ 这个脚本达到了预期的效果。

我的代码如下:

function descriptor()
    return {
        title = "VLC 重命名";
        version = "0.1";
        author = "I";
        shortdesc = "重命名当前文件";
        description = [[
<h1>vlc-rename</h1>"
当您播放文件时,请使用 VLC 重命名
来重命名当前文件]];
    }
end

function removeItem()
    local id = vlc.playlist.current()
    vlc.playlist.delete(id)
    vlc.playlist.gotoitem(id + 1)
    vlc.deactivate()
end

function activate()
    local item = vlc.input.item()
    local uri = item:uri()
    oldFile = vlc.strings.decode_uri(string.gsub(uri, "^file:///", ""))

    d = vlc.dialog( "重命名对话框" )
    d:add_label("文件名")
    w = d:add_text_input(oldFile, 1, 5,200 ,30)
    d:add_button("确定", click_ok)
    d:show()

end

function click_ok()
    local newFile = w:get_text()
    vlc.msg.info("[vlc-rename] 正在重命名:" .. oldFile .. " 为 " .. newFile)
    if newFile ~=  oldFile then
        removeItem()
        retval, err = os.rename(oldFile,newFile)
        vlc.msg.info("[vlc-rename] 重命名结束")

        if (retval == nil) then
            vlc.msg.err("[vlc-rename] 失败:" .. err)
        end
    end
    d:delete()
    vlc.deactivate()
end

function deactivate()
    vlc.deactivate()
end

function close()
    deactivate()
end

function meta_changed()
end

这段代码输出了来自 os.rename() 函数的错误: lua error: [vlc-rename] 失败:[我的文件名] 权限被拒绝 无论升级到什么等级。

我使用的是 Windows 10 64 位和 VLC 3.03。 由于这是我的第一个 lua 脚本,我欢迎任何意见。

点赞
用户15592404
用户15592404

我可能是错的,但是您要重命名的文件可能已经被其他地方或VLC打开(您说您想要重命名“当前文件”)。

2021-04-12 21:03:48