I have a script:
open System
open System.IO
let fileSize path =
try
Some((new FileInfo(path)).Length)
with
| e ->
printfn "%A" e
None
let dirSize dir =
Directory.GetFiles(dir,"*",SearchOption.AllDirectories)
|> Array.map fileSize
|> Array.map (Option.defaultValue 0L)
|> Array.reduce (+)
dirSize """C:\Users\xxx\Documents""";;
I get a System.UnauthorizedAccessException running it.
I try to run cmd or fsi as administrator ,but either worked.
I find a solution used in fsharp program by using Manifest file.
But the --win32manifest option can't be used in fsi(it's an option of fsc).
error FS0243: Unrecognized option: '--win32manifest'.
Is there any solution to request UAC in script?
(I know how to fix the script above by replacing the GetFiles method to catch the exception)
I can say after a bit of research that is is not a .FSX issue, I was able to replicate the problem in visual studio in C# and in F# applications. Here is a link to a similar issue. I think the solution would be to use a folder that you do have full permissions to (anything in my documents is iffy), or use a solution like this as a starting point.