Lua-删除非空目录 [英] Lua - Delete non-empty directory

查看:96
本文介绍了Lua-删除非空目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试删除 Lua 中的非空目录,但没有成功,

I'm trying to remove non-empty directory in Lua but without success,

我尝试了以下操作:

os.remove(path_to_dir)

并收到错误:目录不为空39 path_to_dir

也尝试过:

require ('lfs')
lfs.rmdir(path_to_dir)

并收到错误:目录不为空'

And got the error: Directory not empty'

值得一提的是,我对 path_to_dir

感谢您的帮助.

推荐答案

您可以遵循@EgorSkriptunoff的建议,并使用特定于操作系统的命令来删除非空目录,或者使用lfs获取文件/子目录的列表(对于例如,如在此SO答案中所述),然后使用 os.remove逐个删除它们.

You can either follow @EgorSkriptunoff's suggestion and use OS-specific commands to remove non-empty directories or get the list of files/sub-directories using lfs (for example, as described in this SO answer) and delete them one-by-one using os.remove.

这篇关于Lua-删除非空目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆