Archive: Hot to get install drive?


Hot to get install drive?
I want to use the sysGetDiskFreeSpaceEx function to get the free space at the install path. But this function seems to accept only drive letters and not directories. Is there a way to get only the drive letter for the path that the user has chosen to install like $INSTDIR?



...
StrCpy $R0 $INSTDIR 2 0
...

This would copy C: to $R0 if $INSTDIR were C:\Program Files\foo.

Name "Output"
OutFile "Output.exe"

!include "FileFunc.nsh"
!insertmacro DriveSpace

Section
${DriveSpace} "$INSTDIR" "/D=F /S=M" $R0

IfErrors +2
MessageBox MB_OK "$$R0={$R0}"
SectionEnd

Thanks to both of you for the replies!

The suggestion of goldy1064 is the easiest, but will not work in a case when a network device with a longer root name is chosen.

The suggestion of Instructor is elegant one, but still it can not work if the target folder does not exist as it is usually. So after searching I found the ${GetRoot} function from the FileFunc plug-in which gives the root element of a path. This way and together with the ${DriveSpace} function it worked, because the root element is implied to always exist. I think it will work also with
System::Call '${sysGetDiskFreeSpaceEx}(r1,.r2,,.)'
combined with ${GetRoot}.


it can not work if the target folder does not exist
Yep, you are right, I miss that. Good that you found ${GetRoot}.