2016-09-28 76 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