1

I have images in 100 folders and the search results are slow, so I want to access those images, so maybe I wanna do it with python(if it is faster), in the way that when we select all the files, and drag and drop them in windows. then I realized that drag and drop in windows uses Component Object Model this source.

So I want to know is there any way in python to have COMs of the image files in those 100 folders in the same place (a specific folder)? or in other words can we create COMs of other files, (equivalent of shortcuts), cause I know shortcuts for my purpose won't work.

The question in general is about how to access direct handles or COMs of files of different folders in one folder? if it's possible, please tell me how? to be simpler I want to have similar function of file shortcuts but not 'shortcuts' existing in windows, because for my purpose 'shortcuts' won't work, so I think it can be done with COMs.

tkinter equivalent question: let me ask my question in other way, lets think I want to make a windows file search application in python with some library like tkinter, so one background part of my code finds the file paths of desired search results, and other part in gui('gui part'): wants to show the result files with ability of opening files from that gui or drag files from gui to other folder or applications, so how should I do the 'gui part'?

this tutorial suggested by @Thingamabobs is about getting external files into window(gui) of app, but I want the opposite, I mean having file handles to open, something like windows explorer

My question maybe wrong in case of misunderstanding the concept of COMs, so please provide me more relevant sources of use case of mine. finally if the title seems to be unsuitable, feel free to change it.

  • Why do you want to use COM and not simply file operations? – Corralien Mar 03 '22 at 21:36
  • @Corralien I didnt get ur question? is there any other way to drag images from 100 folders and drop it to some image viewer app? – ahmad mirzaee Mar 03 '22 at 21:42
  • I'm sorry, I missed the part "Image viewer app"! – Corralien Mar 03 '22 at 21:45
  • Maybe you should take a look to pyautogui and [here](https://pyautogui.readthedocs.io/en/latest/mouse.html) – Corralien Mar 03 '22 at 21:48
  • I want to have file handles or COMs, so later drag and drop those images some where(maybe to image viewer in order to view them in image viewer), to be simpler I want to have similar function of file shortcuts but not 'shortcuts' existing in windows cause for my purpose shortcuts won't work, so I think it can be done with COMs. – ahmad mirzaee Mar 03 '22 at 21:49
  • @corralien it probably can't or preferably can't be done with pyautogui, so let me ask my question in other way, let think I want to make a windows file search in python with some library like tkinker, so one background part of my code finds the file paths of desired search results, and one part in gui('gui part'): wants to show the files with ability of opening files from that gui or drag files from gui to other folder or applications, so how should I do the 'gui part' – ahmad mirzaee Mar 03 '22 at 21:58
  • Are you asking about the GUI part of the problem, or the backend which does the searching? If the latter, please remove the [tkinter] tag. – Bryan Oakley Mar 03 '22 at 22:24
  • the gui part, I think I just emphasized on it!! the specific of how to show files with ability to click on and etc in 'gui part', and I think my question is a tkinter tag question also. – ahmad mirzaee Mar 03 '22 at 22:29
  • Your question is far to broad to give an answer. For the com part, you will need to wrap the *drag and drop target* with ctypes or similar. Further you need to learn how to react to user events and last but not least you will have to learn to work with files. You may consider to search just for drag and drop tkinter, I remember there is an existing extension available. – Thingamabobs Mar 03 '22 at 22:35
  • @Thingamabobs can you provide me some resources, in udemy or sites to read about this? btw are u suggesting that it's possible to access COM of a file? – ahmad mirzaee Mar 03 '22 at 22:38
  • I use the msdn documentation and pywin32, pytoncom in this case. I haven't found an easy way to go for it yet and its really confusing especially if you don't know C, like me. I recommend searching *tkinter drag and drop* and see if it satisfy your needs before going down the hard way. – Thingamabobs Mar 03 '22 at 22:44
  • 1
    [See this tutorial](https://youtu.be/JIy0QjwQBl0) – Thingamabobs Mar 03 '22 at 22:53
  • it seems I cant upvote you in comments – ahmad mirzaee Mar 03 '22 at 22:55
  • 2
    Does this answer your question? [How to Install and Use TkDnD with Python Tkinter on OSX?](https://stackoverflow.com/questions/25427347/how-to-install-and-use-tkdnd-with-python-tkinter-on-osx) – Thingamabobs Mar 03 '22 at 22:57
  • Im not sure is it useful or not, maybe I want to drag and drop other way around, I mean from tkinter to windows. so I should first install TKdnd and try tutorial – ahmad mirzaee Mar 03 '22 at 23:03
  • the tutorial was about getting external files into window(gui) of app, but I want the reverse – ahmad mirzaee Mar 03 '22 at 23:37

1 Answers1

2

Based on an interpretation of the question, the following is an initial summary approach to a solution.

"""
This module will enable easy access to files spread across 100 plus
directories. A file should be as easy to open as clicking on a link.

Analysis:
Will any files be duplicated in any other directory? Do not know.
Will any file name be the same as another file in a different directory? Do
not know.

Initial design in pseudocode:
> Capture absolute path to each file in each directory.
> Store files information in python data structure
    > for instance a list of tuples <path>,<filename>
> Once a data structure is determined use Tkinter, ttk.treeview to open a
file as easy as clicking on a link in the tree.
"""
Carl_M
  • 861
  • 1
  • 7
  • 14
  • ttk.treview can be configured to click on an item in the tree to execute a command. The command can be a file open command. – Carl_M Mar 04 '22 at 01:16
  • sorry can it be used for mass file drag and drop? last comment was a mistake. – ahmad mirzaee Mar 04 '22 at 01:51
  • 1
    Mass file drag and drop could be done from treeview. But there might be better (faster, better interface) alternatives. My pseudo design emphasized approximating, "The question in general is about how to access direct handles or COMs of files of different folders in one folder?" – Carl_M Mar 04 '22 at 02:02
  • can you provide the code for the treeview and the link part – ahmad mirzaee Mar 04 '22 at 10:46