Click here to Skip to main content
16,016,760 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to make a simple application using Python language and GTK, and the first obstacle is that I want to add my application to the open-with list of an extension like .txt, and that was not hard to find by Google, but my main issue is when the user open any .txt file from the file-manager using my application, I want to get the path of the file followed by its filename + extension, then I want all of them to be stored to a variable or to a text file like this:

/path_to_the_file/filename.extension


Thanks.

What I have tried:

I searched for the topic, but all I have found is how to use open with statement.
Posted
Updated 10-Jul-22 7:46am
Comments
0x01AA 19-Dec-21 10:59am    
Most probaly you will find that in something like command line parameters?
I assume also available in Linux....

See How to Add or Remove Programs in the Open With Menu in Your Registry[^]. The path should automatically be set as one of the command line parameters to your application.
 
Share this answer
 
I figured out the answer to my question by myself a while ago, and I will share it here for others to find.

To get the path of the file opened by your Python application, you can use this code:

os.getcwd()


And to get the path and the filename of the file opened by your Python application, you can use this code:

sys.argv[1:]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900