删除目录中的空csv文件-R [英] Delete empty csv files in directory - R
本文介绍了删除目录中的空csv文件-R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的文件夹中有很多csv文件(1.csv,2.csv ....,20.csv),但其中一些是空的(5.csv,8.csv).空文件甚至包含大约4个字节的大小,而不是大小0.
我需要在目录中删除它们,并想在R中实现.这可能吗?感谢任何帮助!
I have many csv files in a folder (1.csv,2.csv....,20.csv) but a few of them are empty (5.csv,8.csv). The empty files even contain a size around 4 bytes and are not size 0.
I need to delete them in the directory and I want to achieve this in R. Is this possible? Appreciate any help!
推荐答案
R.utils
包中的函数countLines()
可以完成此任务:
The function countLines()
from R.utils
package does the job:
library(R.utils)
lapply(Filter(function(x) countLines(x)==0, list.files(pattern='.csv')), unlink)
这篇关于删除目录中的空csv文件-R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文