The CommonFolders module
This tutorial shows the use of the CommonFolders module. It simplifies runtime access to various common folder locations on the system, including folders related to the current user, the shared user folders, system wide folders, and folders specific to the currently executing process.
This is particularly useful when combined with the RelativePath type provider for working with project data and deployed. For example, the following copies a file from the project's doc\contents to the user's roaming application data folder.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: |
|
The CommonFolders module supports pulling data from various locations, based on any provided UserPath, SharedPath, SystemPath, or ApplicationPath. Note that many of these paths are wrappers around Environment.GetFolderPath, though a few pull from other APIs.
Some examples of getting common folders include:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: |
|
Full name: CommonFolders.userAppData
from FSharp.Management
Full name: FSharp.Management.CommonFolders.GetUser
| RoamingApplicationData = 26
| LocalApplicationData = 28
| Desktop = 16
| Documents = 5
| Pictures = 39
| Videos = 14
| Favorites = 6
| Startup = 7
Full name: FSharp.Management.PathIdentifiers.UserPath
Full name: CommonFolders.Docs
Full name: FSharp.Management.RelativePath
Full name: CommonFolders.currentFile
Full name: CommonFolders.exePath
Full name: FSharp.Management.CommonFolders.GetApplication
| EntryPointLocation = 0
| EntryPointShadowCopiedLocation = 1
| FSharpManagementLocation = 2
| FSharpManagementShadowCopiedLocation = 3
Full name: FSharp.Management.PathIdentifiers.ApplicationPath
Full name: CommonFolders.sourcePath
static val DirectorySeparatorChar : char
static val AltDirectorySeparatorChar : char
static val VolumeSeparatorChar : char
static val InvalidPathChars : char[]
static val PathSeparator : char
static member ChangeExtension : path:string * extension:string -> string
static member Combine : params paths:string[] -> string + 3 overloads
static member GetDirectoryName : path:string -> string
static member GetExtension : path:string -> string
static member GetFileName : path:string -> string
...
Full name: System.IO.Path
Path.Combine(path1: string, path2: string) : string
Path.Combine(path1: string, path2: string, path3: string) : string
Path.Combine(path1: string, path2: string, path3: string, path4: string) : string
Full name: CommonFolders.targetPath
static member CreateDirectory : path:string -> DirectoryInfo + 1 overload
static member Delete : path:string -> unit + 1 overload
static member EnumerateDirectories : path:string -> IEnumerable<string> + 2 overloads
static member EnumerateFileSystemEntries : path:string -> IEnumerable<string> + 2 overloads
static member EnumerateFiles : path:string -> IEnumerable<string> + 2 overloads
static member Exists : path:string -> bool
static member GetAccessControl : path:string -> DirectorySecurity + 1 overload
static member GetCreationTime : path:string -> DateTime
static member GetCreationTimeUtc : path:string -> DateTime
static member GetCurrentDirectory : unit -> string
...
Full name: System.IO.Directory
Directory.CreateDirectory(path: string, directorySecurity: System.Security.AccessControl.DirectorySecurity) : DirectoryInfo
static member AppendAllLines : path:string * contents:IEnumerable<string> -> unit + 1 overload
static member AppendAllText : path:string * contents:string -> unit + 1 overload
static member AppendText : path:string -> StreamWriter
static member Copy : sourceFileName:string * destFileName:string -> unit + 1 overload
static member Create : path:string -> FileStream + 3 overloads
static member CreateText : path:string -> StreamWriter
static member Decrypt : path:string -> unit
static member Delete : path:string -> unit
static member Encrypt : path:string -> unit
static member Exists : path:string -> bool
...
Full name: System.IO.File
File.Copy(sourceFileName: string, destFileName: string, overwrite: bool) : unit
Full name: CommonFolders.userLocalAppData
Full name: CommonFolders.userDesktop
Full name: CommonFolders.windows
Full name: FSharp.Management.CommonFolders.GetSystem
| Windows = 36
| SystemX86 = 41
| System = 37
| Temp = -1
Full name: FSharp.Management.PathIdentifiers.SystemPath
Full name: CommonFolders.sharedAppData
Full name: FSharp.Management.CommonFolders.GetSharedUser
| ApplicationData = 35
| Documents = 46
| Desktop = 25
| Music = 53
| Pictures = 54
| Video = 55
Full name: FSharp.Management.PathIdentifiers.SharedPath