4

The folders which are open are shown in taskmanager. Perhaps there is a way to access this information with batch or powershell or third party command-line?

explorer-taskmanager.webp

I have also enabled the Restore previous folder windows at logon option... S5032-Folder-Options.webp

So I wonder where the paths of the previously open folder windows is saved.. in regedit? Or in a temporary file somewhere?

1

1 Answer 1

7

Don't know where folders are saved at shutdownn, but to get info on open folders in PowerShell,use the shell.application COM object:

@((New-Object -com shell.application).Windows()).Document.Folder | select Title , { $_.Self.Path }

Sample Output

PS C:\...\keith>@((New-Object -com shell.application).Windows()).Document.Folder | select Title , { $_.Self.Path }

Title         $_.Self.Path
-----        --------------
This PC      ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}
Quick access ::{679F85CB-0220-4080-B29B-5540CC05AAB6}
Windows (C:) C:\
SendTo       C:\Users\keith\AppData\Roaming\Microsoft\Windows\SendTo


To get humann-friendly names for virtual folders as well as see the full namespace path, you can define a recursive function that gives you the full path (rooted in the virtual Desktop):

Function NSPath ($oFldr)
{
    If ($oFldr.ParentFolder )
    {
        '{0}\{1}'-f (NSPath $oFldr.ParentFolder), $oFldr.Title
    }
    Else
    {
        '\' # or $oFldr.Title
    }
}

Then use the function like so:

@((New-Object -com shell.application).Windows()).Document.Folder | %{ NSPath $_ }

OUtput:

PS C:\...\keith>@($shell.Windows()).Document.Folder | %{ NSPath $_ }
\\This PC
\\Quick access
\\Keith Miller\Documents
\\This PC\Documents
\\This PC\Windows (C:)\Users\keith\Documents

To make it easy to use from within batch, add the function to your PowerShell profile like so:

@'
New-Object -com shell.application
Function NSPath ($oFldr)
{
    If ($oFldr.ParentFolder )
    {
        '{0}\{1}'-f (NSPath $oFldr.ParentFolder), $oFldr.Title
    }
    Else
    {
        '\' # or $oFldr.Title
    }
}
'@ | add-content $PROFILE

and then both the function NSPath and the COM object $Shell are available for use whenever you launch PowerShell.

5
  • Now the question is.. how do I cut this into segments and save each folder path alone into a text list?
    – goldnick7
    Jan 16 at 6:55
  • 1
    Please clarify. Just the folder paths? @((New-Object -com shell.application).Windows()).Document.Folder.Self.Path. Want that list on the clipboard? add ` | Out-String | Set-Clipboard ` to the command. To a file? Add ` | Set-Content 'C:\Path\To\File.txt' ` . Jan 16 at 8:55
  • This is what I wanted --> powershell @^(^(New-Object -com shell.application^).Windows^(^)^).Document.Folder.Self.Path >> openfolderspaths.txt
    – goldnick7
    Jan 16 at 19:40
  • Cool. If you're not using the paths for shell operations, "::{CLSID}" may not be the most useful form. You can add the NSPath function to your PowerShell profile and then it would be available to give you human-friendly paths for virtual folders. Jan 16 at 19:48
  • See edited answer for function. I know nothing of batch syntax, I alwasys used VBScript before PowerShell. What do you need from batch that you can't get from PPowerShell? Jan 16 at 21:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.