自动删除文件/文件夹 [英] Automatically Delete Files/Folders

查看:77
本文介绍了自动删除文件/文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以用很少的R命令行自动删除所有文件或文件夹? 我知道unlink()file.remove()函数,但是对于那些函数,您需要定义一个字符向量,其中包含要删除的文件的所有名称.我正在寻找一些列出特定路径(例如'C:/Temp')中的所有文件或文件夹,然后删除具有特定名称(无论其扩展名如何)的所有文件的东西.

Is there any way to automatically delete all files or folders with few R command lines? I am aware of the unlink() or file.remove() functions, but for those you need to define a character vector with exactly all the names of the files you want to delete. I am looking more for something that lists all the files or folders within a specific path (e.g. 'C:/Temp') and then delete all files with a certain name (regardless of its extension).

非常感谢您的帮助!

推荐答案

也许您只是在寻找file.removelist.files的组合?也许像这样:

Maybe you're just looking for a combination of file.remove and list.files? Maybe something like:

do.call(file.remove, list(list.files("C:/Temp", full.names = TRUE)))

我想您可以使用grepgrepl将文件列表过滤到名称与特定模式匹配的文件列表,不是吗?

And I guess you can filter the list of files down to those whose names match a certain pattern using grep or grepl, no?

这篇关于自动删除文件/文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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