It should be possible to retrieve the location of all "special folders" instead of hardcoding them (or assuming they are just subfolders of the user's profile folder).
As of today, [Environment]::GetFolderPath() (which reportedly relies on SHGetKnownFolderPath()) doesn't support all KNOWNFOLDERID's. Here's a few of the ones that are not supported:
FOLDERID_Downloads
FOLDERID_DocumentsLibrary
FOLDERID_CameraRoll
I understand this might be a .Net Core issue, not a PowerShell Core issue (haven't checked out the code yet).
c:\users\joe\Downloads
MethodException: Cannot convert argument "folder", with value: "Downloads", for "GetFolderPath" to type "System.Environment+SpecialFolder": "Cannot convert value "Downloads" to type "System.Environment+SpecialFolder". Error: "Unable to match the identifier name Downloads to a valid enumerator name. Specify one of the following enumerator names and try again:
Desktop, Programs, MyDocuments, Personal, Favorites, Startup, Recent, SendTo, StartMenu, MyMusic, MyVideos, DesktopDirectory, MyComputer, NetworkShortcuts, Fonts, Templates, CommonStartMenu, CommonPrograms, CommonStartup, CommonDesktopDirectory, ApplicationData, PrinterShortcuts, LocalApplicationData, InternetCache, Cookies, History, CommonApplicationData, Windows, System, ProgramFiles, MyPictures, UserProfile, SystemX86, ProgramFilesX86, CommonProgramFiles, CommonProgramFilesX86, CommonTemplates, CommonDocuments, CommonAdminTools, AdminTools, CommonMusic, CommonPictures, CommonVideos, Resources,
LocalizedResources, CommonOemLinks, CDBurning""
````
❯ $PSVersionTable
Name Value
---- -----
PSVersion 7.0.0-preview.6
PSEdition Core
GitCommitId 7.0.0-preview.6
OS Microsoft Windows 10.0.17134
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
````
@sba923 see this document from MS: https://docs.microsoft.com/en-us/windows/win32/shell/knownfolderid
While the Downloads folder is listed, you'll note it has no CIDL equivalent. I don't know the history, but looking at the method you're using, it is noted that accepted values are based on CIDL values (which there aren't any for the Downloads folder). See the Remarks section here: https://docs.microsoft.com/en-us/dotnet/api/system.environment.getfolderpath
See also this StackOverflow answer for some c# examples which can be adapted for use in Powershell: https://stackoverflow.com/questions/10667012/getting-downloads-folder-in-c/21953690
My guess would be that the GetFolderPath method hasn't been updated in a while; fixing that would definitely be a .net Core issue :slightly_smiling_face:
The KNOWNFOLDERID constants represent GUIDs that identify standard folders registered with the system as Known Folders.
Gets the path to the system special folder that is identified by the specified enumeration.
Stack OverflowI have made some code that will search directories and display files in a listbox. DirectoryInfo dinfo2 = new DirectoryInfo(@"C:\Users\Hunter\Downloads"); FileInfo[] Files2 = dinfo2.GetFiles("*.s...
Shall I create a C# repro, open a .Net Core issue and link it from here?
I'd say that's probably the best idea. Might want to check the existing issues on https://github.com/dotnet/corefx to see if there's already an issue you can add to, but otherwise definitely open a new issue for it. 🙂
GitHub
CoreFX is the foundational class libraries for .NET Core. It includes types for collections, file systems, console, JSON, XML, async and many others. - dotnet/corefx
(https://github.com/dotnet/corefx/issues/42733) -> (https://github.com/dotnet/runtime)
GitHub
.NET is a cross-platform runtime and libraries, for cloud, IoT and desktop apps. It includes a garbage collector, JIT compiler, primitive data types and class libraries. - dotnet/runtime
This issue has been marked as external and has not had any activity for 1 day. It has been be closed for housekeeping purposes.