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)