- 论坛徽章:
- 0
|
- #coding=utf-8
- '''
- * 恢复收藏家内容的工具
- * 版权所有
- * @author t6760915<t6760915@gmail.com>
- * @version $Id: modifyFavorites.py $
- '''
- import os
- import sys
- #定义方法,删除某个目录下所有文件夹和文件
- def delAll(parentDir, topDir):
- parentDir = os.path.normpath(parentDir)
- topDir = os.path.normpath(topDir)
- parentDirGbk = parentDir.decode('utf-8', 'ignore').encode('gbk', 'ignore')
- topDirGbk = topDir.decode('utf-8', 'ignore').encode('gbk', 'ignore')
- if not os.path.exists(parentDirGbk):
- return True
- if os.path.isdir(parentDirGbk):
- for subDir in os.listdir(parentDirGbk):
- subDir = subDir.decode('gbk', 'ignore').encode('utf-8', 'ignore')
- subDir = os.path.normpath('%s/%s' % (parentDir, subDir))
- delAll(subDir, topDir)
-
- if topDir == parentDir:
- pass
- else:
- try:
- os.rmdir(parentDirGbk)
- except:
- pass
-
- elif os.path.isfile(parentDirGbk):
- try:
- os.unlink(parentDirGbk)
- except:
- pass
- else:
- pass
-
- #定义收藏夹位置
- #FavoritesDir = 'C:/Documents and Settings/ko/Favorites',ko是你的用户名
- FavoritesDir = 'C:/Documents and Settings/ko/Favorites'
- delAll(FavoritesDir, FavoritesDir)
- #定义收藏夹地址字典
- FavoritesSites = []
- FavoritesSites.append(['链接', 'http://www.google.com/'])
- FavoritesSites.append(['链接', 'http://www.baidu.com/'])
- FavoritesSites.append(['链接', 'http://www.verycd.com/'])
- FavoritesSites.append(['链接', 'http://www.gougou.com/'])
- FavoritesSites.append(['链接', 'http://www.tianya.cn/'])
- FavoritesSites.append(['', 'http://www.python.org/ftp/python/'])
- FavoritesSites.append(['', 'http://www.djangoproject.com/'])
- FavoritesSites.append(['', 'http://www.webpy.org/'])
- FavoritesSites.append(['', 'http://bbs.chinaunix.net/'])
- FavoritesSites.append(['', 'http://www.javaeye.com/'])
- FavoritesSites.append(['', 'http://community.csdn.net/'])
- FavoritesSites.append(['', 'http://groups.google.mw/'])
- FavoritesSites.append(['', 'http://www.oschina.net/'])
- #将定义好的地址写入文件
- for site in FavoritesSites:
- dirName,url = site
- if not url:
- continue
- if not url.startswith('http'):
- continue
- if not '/' in url:
- continue
- subDirPath = os.path.normpath(FavoritesDir+'/'+dirName).decode('utf-8', 'ignore').encode('gbk', 'ignore')
-
- if os.path.exists(subDirPath):
- pass
- else:
- try:
- os.makedirs(subDirPath)
- except:
- pass
- urlName = '%s.url' % url.split('//')[1].split('/')[0].replace(':', '-')
- subFilePath = os.path.normpath(FavoritesDir+'/'+dirName+'/'+urlName).decode('utf-8', 'ignore').encode('gbk', 'ignore')
- fileContent = '''[InternetShortcut]\nURL=%s''' % url
- try:
- fp = open(subFilePath, 'w')
- fp.write(fileContent)
- fp.close()
- except:
- pass
- print 'modifyFavorites success!'
- os.system('pause')
- sys.exit(0)
复制代码
modifyFavorites.rar
(1.16 KB, 下载次数: 56)
|
|