1 Star 0 Fork 20

zhaoqil/PythonUIAutomation4Windows

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
walk_test.py 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
yinkaisheng 提交于 2015-12-28 10:49 . upload
#!python3
# -*- coding: utf-8 -*-
import os
import automation
def walkDir():
def GetDirChildren(dir):
if os.path.isdir(dir):
subdirs = []
files = []
for it in os.listdir(dir):
absPath = os.path.join(dir, it)
if os.path.isdir(absPath):
subdirs.append(absPath)
else:
files.append(absPath)
return subdirs + files
for it, depth in automation.WalkTree(r'c:\Program Files\Internet Explorer', getChildrenFunc= GetDirChildren, includeTop= True):
print(it, depth)
def walkDesktop():
def GetFirstChild(control):
return control.GetFirstChildControl()
def GetNextSibling(control):
return control.GetNextSiblingControl()
desktop = automation.GetRootControl()
for control, depth in automation.WalkTree(desktop, getFirstChildFunc= GetFirstChild, getNextSiblingFunc= GetNextSibling, includeTop= True, maxDepth= 1):
print(' ' * depth * 4 + str(control))
def main():
walkDir()
print()
walkDesktop()
if __name__ == '__main__':
main()
input('press enter to exit')
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/xxrl2018/PythonUIAutomation4Windows.git
git@gitee.com:xxrl2018/PythonUIAutomation4Windows.git
xxrl2018
PythonUIAutomation4Windows
PythonUIAutomation4Windows
master

搜索帮助