2016-09-28 46 views
2

我想计算的R的目录的大小我试图用list.info功能,通过unfortunably下面的符号链接,所以我的结果有偏差:计算目录的在R上的大小

# 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

感谢

回答

3

我终于用这样的:

system('du -s') 
3
system('powershell -noprofile -command "ls -r|measure -s Length"') 

参考文献:

  1. https://technet.microsoft.com/en-us/library/ff730945.aspx
  2. Get Folder Size from Windows Command Line
  3. https://stat.ethz.ch/R-manual/R-devel/library/base/html/system.html
  4. https://superuser.com/questions/217773/how-can-i-check-the-actual-size-used-in-an-ntfs-directory-with-many-hardlinks

你也可以利用cygwin,如果你有它;这可让您使用Linux命令并获得可比较的结果。此外,在我上面给出的最后一个链接中使用Sysinternals还有一个很好的解决方案。

+0

其实我跑R于Linux的,但是'系统()'命令应该就可以工作了。 – carmellose