os.execute("ls")print(os.rename("lua_dir", "lua_dir_1"))print(os.rename("lua_file", "lua_file_1"))os.execute("ls")print(os.rename("lua_file", "lua_file_1"))print(os.rename("lua_dir_1", "lua_file_1"))print(os.rename("lua_dir_1", "exist_dir"))
输出如下:exist_dir lua_dir lua_file rename.luatruetrueexist_dir lua_dir_1 lua_file_1 rename.luanil No such file or directory 2nil Not a directory 20nil Directory not empty 39
os.rename总结os.rename用于重命名文件或者目录,如果newpath存在且能被替换时会被自动替换,如果调用失败则会返回3个值,分别是nil,错误信息,错误码(图片来源网络,侵删)
0 评论