简体   繁体   中英

Command line args in F# fsx

I run my .fsx file like

>fsi A.fsx

In this file I read csv with CsvProvider that has to have path to csv data.

type Data = CsvProvider<"my_data.txt", ";", Schema

I need to pass file name as command line argument and it is possible

 >fsi A.fsx my_data.txt

I can read it like

let originalPath = fsi.CommandLineArgs.ElementAt(1)

Problem is, that file name used in CsvProvider constructor needs to be constant and command line argument is not. How I can initialize CsvProvider from command line argument?

The value inside the angle brackes <"my_data.txt"...> specifies an example format file and is checked at compile time, hence the need for it to be a constant string. Assuming your .fsx script merely wants to load a different CSV file of the same general format, you would use

let contents = Data.Load(originalPath)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM