Python win32api 模块,GetWindowsDirectory() 实例源码
我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用win32api.GetWindowsDirectory()。
def which_file(fname):
"""prints paths for fname where fname can be found,
in case of .dll loads it"""
files = []
path = win32api.GetEnvironmentVariable('PATH')
# try paths as described in MSDN
dirs = [os.getcwd(), win32api.GetSystemDirectory(), win32api.GetWindowsDirectory()] + path.split(';')
dirs_norm = []
dirs_l = []
for d in dirs:
dn = d.lower()
if dn not in dirs_l:
dirs_l.append(dn)
dirs_norm.append(d)
for d in dirs_norm:
fname2 = os.path.join(d, fname)
if os.path.exists(fname2):
if fname2 not in files:
files.append(fname2)
if files:
print('\n'.join([get_file_info(f) for f in files]))
h = 0
if fname.lower().endswith('.dll'):
print('\ttrying to load "%s" ...' % (fname))
try:
h = win32api.LoadLibrary(fname)
if h:
dll_name = win32api.GetModuleFileName(h)
print('\t%s loaded' % (dll_name))
except:
print('\tCannot load "%s" !!!' % (fname))
def get_windows_dir():
"""
Return the Windows directory e.g. C:\\Windows.
"""
try:
import win32api
except ImportError:
windir = compat.getenv('SystemRoot', compat.getenv('WINDIR'))
else:
windir = win32api.GetWindowsDirectory()
if not windir:
raise SystemExit("Error: Can not determine your Windows directory")
return windir
def demo():
import glob
winDir=win32api.GetWindowsDirectory()
for fileName in glob.glob1(winDir, '*.bmp')[:2]:
bitmapTemplate.OpenDocumentFile(os.path.join(winDir, fileName))
def GetTestVideoModule():
global videoControlModule, videoControlFileName
win32ui.DoWaitCursor(1)
videoControlModule = gencache.EnsureModule("{05589FA0-C356-11CE-BF01-00AA0055595A}", 0, 2, 0)
win32ui.DoWaitCursor(0)
if videoControlModule is None:
return None
fnames = glob.glob(os.path.join(win32api.GetWindowsDirectory(), "*.avi"))
if not fnames:
print "No AVI files available in system directory"
return None
videoControlFileName = fnames[0]
return videoControlModule
def demo():
import glob
winDir=win32api.GetWindowsDirectory()
for fileName in glob.glob1(winDir, '*.bmp')[:2]:
bitmapTemplate.OpenDocumentFile(os.path.join(winDir, fileName))
def GetTestVideoModule():
global videoControlModule, videoControlFileName
win32ui.DoWaitCursor(1)
videoControlModule = gencache.EnsureModule("{05589FA0-C356-11CE-BF01-00AA0055595A}", 0, 2, 0)
win32ui.DoWaitCursor(0)
if videoControlModule is None:
return None
fnames = glob.glob(os.path.join(win32api.GetWindowsDirectory(), "*.avi"))
if not fnames:
print("No AVI files available in system directory")
return None
videoControlFileName = fnames[0]
return videoControlModule
def get_windows_dir():
"""
Return the Windows directory e.g. C:\\Windows.
"""
try:
import win32api
except ImportError:
windir = compat.getenv('SystemRoot', compat.getenv('WINDIR'))
else:
windir = win32api.GetWindowsDirectory()
if not windir:
raise SystemExit("Error: Can not determine your Windows directory")
return windir