# Does any know how to get the paths of current opened locations in file explorer?

Does anyone know if there is a builtin way to get all opened locations in the file explorer?

Like for browsers, the browser itself remembers the last opened locations. So even if it crashes one can restore them. But for file explorer, once the processes crash for some reason there is no way to get that information back.

Maybe there is some Developer context function or maybe someone knows how to get this information using the NetLink functionality? So I can periodically store them in my notebook so I don't lose them.

• What is the file explorer? If you mean the interface for picking a file that Mathematica will open up, then I’m pretty sure the answer is no. That’s implemented by the OS so both the OS and Mathematica would need to expose some API and I’m not sure if either of them do. – b3m2a1 Feb 7 '20 at 19:55

If you are referring to the Windows File Explorer, then we can use NETLink and the Shell API to get a list of open windows:

Needs["NETLink"]
InstallNET[];

shellWindows[] :=
NETBlock@Module[{app, windows, w, item}
, InternalWithLocalSettings[
app = CreateCOMObject["Shell.Application"]
, windows = app@Windows[]
; Table[
InternalWithLocalSettings[
item = windows@Item[w]
, item@Name -> item@LocationURL
, ReleaseCOMObject[item]
]
, {w, 0, windows@Count-1}
] // GroupBy[First->Last]
, Scan[ReleaseCOMObject, {windows, app}]
]
]


This function retrieves an association of the names and file URLs of all open shell windows, grouped by their names. File Explorer windows will all have the name File Explorer on Windows 10 (or Windows Explorer on earlier versions of Windows).

For example:

This function will also return entries for other shell windows that happen to be open, such as Internet Explorer. But such entries will be grouped under other keys.

• I have a few questions, does the manual release of COM objects necessary? Doesn't the NETBlock automatically release them when it ends? Secondly, what is the purpose of InternalWithLocalSettings? Thirdly, is UninstallNET[] needed to completely close all connections? Fourthly, once you release the COM object calling any of its methods obviously fails but is there a function to check whether COM object bound to a WL symbol is active or has been released? Finally, is there a function to get all the method names for the COM object? – user13892 Feb 8 '20 at 14:15
• Also, was the localization of w necessary? Isn't it automatically localized since it is a Table variable? – user13892 Feb 8 '20 at 14:20
• NETBlock only releases .NET objects. COM objects need manual release. WithLocalSettings is used to ensure the release even if an error occurs within the body. UninstallNET can be used if you know you are done with all .NET interaction. I usually leave it open for the whole session. I do not know of a way to test a released COM object. The only ways I know to get a list of COM methods is to read the docs (which I did here) or inspect the type library (if you have one available). Yes, w is necessary. – WReach Feb 8 '20 at 14:48
• Thank you @WReach for the answers! Do you also know how to get the list of all currently running programs being displayed on the windows taskbar? If you want I can open a new question. – user13892 Feb 8 '20 at 15:20
• I don't know how to do that, but you might start from something like this. – WReach Feb 8 '20 at 15:29