How to find the path of a file in windows with Python

1

My question is, how can I get the path of a specific program in windows for this case suppose word that the default executable is WINWORD.EXE .

But even though the executable is the same in any version, it is not the same route in any machine.

Then

How could I obtain the path in this case from WINWORD.EXE

Example: obetner the xxxxx fields, regardless of the pc     C: \ xxxxx \ xxxxx \ xxxx \ xxxxx \ WINWORD.EXE

NOTE:

Some time ago I read something about os.walk () I do not know if this can be implemented in this case

    
asked by Mystic_Force 22.08.2018 в 23:50
source

1 answer

1

Try the following:

You have to change the base_dir variables for your base directory from where to search. I guess C:/ for your case. And the required file that would be WINWORD.EXE

import os

dir_base = '/usr/'
fichero_requerido = 'perl'

for root, folders, files in os.walk(dir_base):
    for file in files:
        if file == fichero_requerido:
            print('Encontrado '+file+' en '+os.path.join(root, file))
            break
    
answered by 23.08.2018 / 01:26
source