分类:
2008-10-13 16:14:23
## Generate Favorit Web Links # File : makefav.py # Author : Spark Song # Date : 2005-08-23 from win32api import RegQueryValue,RegQueryValueEx,RegOpenKey, RegCloseKey, GetProfileVal from win32con import HKEY_CURRENT_USER import os html_str = '' def trealUrlShortCut(File): if File.find('url') == -1: return val = GetProfileVal('InternetShortcut', 'url', 'about:blank', File) if val == 'about:blank': val = GetProfileVal('DEFAULT', 'BASEURL', 'about:blank', File) globals()['html_str'] = globals()['html_str'] + '' + "" + getFileNameWithoutExt(getFolderName(File)) \ #:~~
+ "" def getFavoritesFolder(): name = 'Favorites' hkey = HKEY_CURRENT_USER subkey = r'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders' hkey = RegOpenKey(hkey, subkey) obj, type = RegQueryValueEx(hkey, name) return obj def getFolderName(Path): path, tail = os.path.split(Path) return tail def getFileNameWithoutExt(File): Filename, Ext = os.path.splitext(File) return Filename def allFileDir(path): for file in os.listdir(path): file_or_dir = os.path.join(path,file) if os.path.isdir(file_or_dir) and not os.path.islink(file_or_dir): globals()['html_str'] = globals()['html_str'] + '' + getFolderName(file_or_dir) allFileDir(file_or_dir) #it's a directory reucursive call to function again else: trealUrlShortCut(file_or_dir) globals()['html_str'] = globals()['html_str'] + '
' allFileDir(getFavoritesFolder()) f = open("out.html", "w") f.write('\n') f.write( html_str) f.close()
注:运行该代码需要安装,其中包含了ActiveState Corp.整合的Python和Python for Windows Extensions。本程序在Windows XP Professional下通过。
为了吸引观众,推广Python,抓个图放在下面,嘿嘿。(下图是上面这段程序在偶机器上的运行效果,老少皆易,一点即得,价格公道,童叟无欺)