如何使用python获取所有已安装程序的列表(文件,列表等)? [英] How can i get a list (file, list, whatever) of all installed programs using python?

查看:166
本文介绍了如何使用python获取所有已安装程序的列表(文件,列表等)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直发现的所有答案都是针对python 2.x,但是我使用的是python3.x.他们还一直在谈论不使用.exe安装的程序.

我需要一种方法来获取安装程序的列表,包括.exe和.msi(以及其他任何安装方法)以及它们各自的安装路径.

此刻,这就是我用来寻找东西的方法:

  import os,字符串从os.path导入连接,getsizeavailableDrives = ['%s:'%d对于string.ascii_uppercase中的d,如果os.path.exists('%s:'%d)]对于范围内的我(len(availableDrives)):用于os.walk(availableDrives [i])中的root,dirs,文件:打印(根)如果文件中有"ds.py":打印('是')别的:打印(否") 

对于那些不想读取它的人,它将搜索每个驱动器上的所有文件夹.我正处于使它略微提高效率的过程中,但是它仍然很耗时,并且我想知道是否在6年后(是的,那是在问问题的时候),是否终于有一种方法来获取这些信息?>

如果是这样,怎么办?并且,如果可能的话,您能给我提供它的代码,但作为学校项目的一小部分,在我需要的时候进行解释.

全力以赴,

卢克

我已经看到其他一些使用cmd的资源来创建一个包含必要信息的文本文件.如果有人可以告诉我该怎么做,我不会使用这种方法

解决方案

我认为您首先必须在必须声明的所有目录中查看文件,因为我认为这不是向您显示所有文件的功能.尝试看一下: http://stackabuse.com/python-list-files-in-a-目录/ https://www.tutorialspoint.com/python/os_walk.htm

All the answers I keep finding are for python 2.X, but I use python 3.X. They also keep talking about not working with .exe installed programs.

I need a way to be able to get a list of installed programs, both .exe and .msi (and any other method of installation as well), along side their respective installation paths.

At the moment, this is what I'm using to find things:

import os, string
from os.path import join, getsize
availableDrives = ['%s:' % d for d in string.ascii_uppercase if os.path.exists('%s:' % d)]
for i in range(len(availableDrives)):
    for root, dirs, files in os.walk(availableDrives[i]):
        print(root)
        if "ds.py" in files:
            print('yes')
        else:
            print("No")

For those that don't want to read it, it searches through all folder on every drive. I'm in the middle of making it slightly more fficient, but it is still time consuming and I was wondering if after 6 years (yes, that was when the questions were asked), theres finally a way to get this information?

If so, how? And if possible, could you give me the code for it but explain it as I need it as a small part of a school project.

Cheers all,

Luke

EDIT: I've seen some other resources using cmd to create a text file containing the necessary information. I wouldn't mid using this method if someone could tell me how to do it

解决方案

i think you have first to see files in all the directory that you have to declare because i think ther's not a function to show u all the files. try to look at that: http://stackabuse.com/python-list-files-in-a-directory/ https://www.tutorialspoint.com/python/os_walk.htm

这篇关于如何使用python获取所有已安装程序的列表(文件,列表等)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆