我想计算R中目录的大小。我试图使用list.info
函数,不幸的是跟随符号链接,所以我的结果有偏见:
# return wrong size, with duplicate counts for symlinks
sum(file.info(list.files(path = '/my/directory/', recursive = T, full.names = T))$size)
如何计算目录的文件大小,以便它给出与Linux相同的结果,例如:以du -s
为例?
由于
答案 0 :(得分:4)
我终于使用了这个:
system('du -s')
答案 1 :(得分:3)
#presets for varibles
nCount = 0
total = 0
average = 0.0
Numbers = []
ValidInt = False
#start of string
nCount = (input("How many numbers? "))
print(nCount)
while not ValidInt:
try:
int(nCount)
ValidInt = True
except:
nCount = input("Please Enter An Interger Number")
#validation loops untill an interger is entered
for x in range (int(nCount)):
Numbers.append(input("Please Enter The Next Number"))
参考文献:
如果你拥有它,你也可以利用cygwin;这使您可以使用Linux命令并获得可比较的结果。此外,在我上面给出的最后一个链接中使用Sysinternals是一个不错的解决方案。
答案 2 :(得分:2)
“ file.size”返回实际大小,磁盘上的大小是磁盘上实际占用的空间量。 检查一下以了解区别。 https://superuser.com/questions/66825/what-is-the-difference-between-size-and-size-on-disk 试试看所有文件的大小:
files<-list.files(path_of_directory,full.names = T)
vect_size <- sapply(files, file.size)
size_files <- sum(vect_size)
答案 3 :(得分:0)
健康的解决方案,可能对检查包裹大小非常有用。
dir_size <- function(path, recursive = TRUE) {
stopifnot(is.character(path))
files <- list.files(path, full.names = T, recursive = recursive)
vect_size <- sapply(files, function(x) file.size(x))
size_files <- sum(vect_size)
size_files
}
cat(dir_size(find.package("Rcpp"))/10**6, "Mb")
#> 14.81649 Mb
由 reprex package (v2.0.0) 于 2021 年 6 月 26 日创建