7

How can I get the total disk space / free disk space of my windows computer ?

If there is no R function, maybe there is a windows command that I could use within the R system function but I wasn't able to find that command.

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
Julien Navarre
  • 7,653
  • 3
  • 42
  • 69
  • 1
    For a `system` solution, take a look at [Free space in a CMD shell](http://stackoverflow.com/questions/293780/free-space-in-a-cmd-shell) (the `dir` command mentioned there should work). – CL. Aug 25 '15 at 10:05

1 Answers1

10

Though I find it really difficult to believe that a Google search for windows cmd disk space came up empty for you, this should provide the information you need w/o the need for admin privileges:

disks <- system("wmic logicaldisk get size,freespace,caption", inter=TRUE)

disks <- read.fwf(textConnection(disks[1:(length(disks)-1)]), 
         widths=c(9, 13, 13), strip.white=TRUE, stringsAsFactors=FALSE)

colnames(disks) <- disks[1,]
disks <- disks[-1,]
rownames(disks) <- NULL

disks

##   Caption   FreeSpace        Size
## 1      A:                        
## 2      C: 52617023488 63898120192
## 3      D:                        

Just thought I'd also add that this answer comes from someone who is primarily an OS X/Linux user.

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
  • 1
    I didn't use the right keywords I guess... I would have prefered find the answer directly with a google search than taking the time to write a question. Anyway thanks, this is exactly what I need ! And indeed it works w/o admin privileges. – Julien Navarre Aug 25 '15 at 10:21
  • Btw why do you set a length of 12 for the 3rd column ? The values of the column "Size" will always be at least the same length as "FreeSpace" no ? – Julien Navarre Aug 25 '15 at 12:56
  • there's a 2 space buffer between them. the 12 avoids any chance of taking the inane MS-DOS `\r`'s along for the ride. – hrbrmstr Aug 25 '15 at 13:07
  • 1
    OK, but it seems to drop the last number of the "Size" value for disk space >~ 93Gb (1e11 bytes). For example : `read.fwf(textConnection("C: 364533350400 481852125184 \r"), widths = c(9, 13, 12), strip.white = TRUE)` Results in : `1 C: 364533350400 48185212518`. And i'm not experiencing troubles using 13+ widths. EDIT : SO drops duplicated spaces in string.. :/ – Julien Navarre Aug 25 '15 at 13:21