1

My problem is that I am making a program that will get file's data as per the folder that the user has opened as a file explorer... and I have surfed the whole internet to find the answer but it seems that this problem is never faced by anybody before. Many answers are related to the current working directory in which project files are situated.

So, I basically want the path for the folder which is currently being viewed by the user in file explorer...

Julian
  • 4,176
  • 19
  • 40
  • 1
    What is file explorer? Do you mean all of them including terminal file explorers like ranger or one specific file explorer? What if the user opens 5 different folders with 5 instances of one file explorer? – Thomas Sablik Feb 11 '21 at 08:42
  • @ThomasSablik Probably a *File explorer* built-in Windows I suppose, that's only I can think of with same name. – jupiterbjy Feb 11 '21 at 08:43
  • @jupiterbjy Can't see Windows in the question. – Thomas Sablik Feb 11 '21 at 08:43
  • A specific one, which a normal user works with on daily basis... like **My PC** in windows. I want the path to folder on which the user is currently on in My PC. For example (D:\Games) – imran-akbar Feb 11 '21 at 08:47
  • Again, what if they have 5 folders open? You mean the one with the focus? – Tomerikoo Feb 11 '21 at 08:52
  • 2
    Does this answer your question? [Obtain Active window using Python](https://stackoverflow.com/questions/10266281/obtain-active-window-using-python) – Tomerikoo Feb 11 '21 at 08:53
  • What if the user opens 5 folders and none of them has focus? – Thomas Sablik Feb 11 '21 at 08:55
  • @TomerikooTomorrow hmmm... this is not giving me the path. it's only gave me the name of the folder in the foreground – imran-akbar Feb 11 '21 at 08:58

1 Answers1

0

Best way I can imagine doing that is write your Python software to use context menu in Explorer. With quick googling I found a interesting library for that: https://pypi.org/project/context-menu/

I suppose that there is no sensible way to read data from another process. That would cause security problems.

ex4
  • 2,289
  • 1
  • 14
  • 21
  • _"I suppose that there is no sensible way to read data from another process. That would cause security problems."_ It's called API. Many programs provide interfaces for this kind of communication: https://learn.microsoft.com/en-us/windows/win32/shell/developing-with-windows-explorer – Thomas Sablik Feb 11 '21 at 09:02
  • @ThomasSablik: thank you for info. I didn't know Windows Explorer provides API. I was thinking scenario trying read data from a process which doesn't provide API or data which isn't provided by API. For example, I hope no one can read data from my banksoftware.exe process. – ex4 Feb 11 '21 at 09:06
  • On Windows you can. That's how most of the game cheating software works. They read memory of the game process and try to interpret the values to change them later. On other operating systems it's difficult or impossible. – Thomas Sablik Feb 11 '21 at 09:07