Export IE Favorites to Mozilla BookMark File Format (VBS)

How to do things, solutions, recipes, tutorials
Post Reply
Message
Author
John Doe
Posts: 1681
Joined: Mon 01 Aug 2005, 04:46
Location: Michigan, US

Export IE Favorites to Mozilla BookMark File Format (VBS)

#1 Post by John Doe »

If you would like to do this from Bash see this post:

Import IE Favorites to Mozilla BookMark File Format (BASH)

I tested this on XPPro with about 4000 bookmarks. It worked great on import to Seamonkey.

Let me know success or problems. It should recurse to any directory depth and get all links.

Copy the following into a *.vbs file (ie, ExportFavs.vbs), click it, and wait for the success message. Your new bookmarks.html file will be on your desktop, open it in IE and make sure the script made it to the end. If it fails at somepoint you will be missing bookmarks in the bookmarks.html file itself.

Code: Select all

'**************************************
' Name: IE Browser Favorites Export
' Description: Make a NETSCAPE-Bookmark-file-1 from IE Favorites
' By: John Doe
'
'This script is released for all Puppy Users to export IE Favorites
'**************************************

Option Explicit
On Error Resume Next

''THERE ARE HERE SO WE DON"T DECLARE THEM 1000 TIMES
Dim colFiles, FileObj

Dim WSHShell
Set WSHShell = WScript.CreateObject("WScript.Shell")

'''''''' Set the Source Folder'''''''''
Dim objFileSystem
Set objFileSystem = Wscript.CreateObject("Scripting.FileSystemObject")
Dim objWSH, strFAV, objFolder
Set objWSH = CreateObject("WScript.Shell") 
strFAV = objWSH.SpecialFolders.Item("Favorites")
Set objFolder = objFileSystem.GetFolder(strFAV)

'''''''' Create Destination File '''''''''
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

Dim objDSH, strDSK, MyFile
Set objDSH = CreateObject("WScript.Shell") 
strDSK = objDSH.SpecialFolders.Item("Desktop")
Set MyFile = fso.CreateTextFile(strDSK & "\bookmarks.html", True)

''''''''  Write DOC TYPE
MyFile.WriteLine("<!DOCTYPE NETSCAPE-Bookmark-file-1>")
MyFile.WriteLine("<!-- This is an automatically generated file.")
MyFile.WriteLine("     It will be read and overwritten.")
MyFile.WriteLine("     DO NOT EDIT! -->")
MyFile.WriteLine("<META HTTP-EQUIV=""Content-Type"" CONTENT=""text/html; charset=UTF-8"">")
MyFile.WriteLine("<TITLE>Bookmarks</TITLE>")
MyFile.WriteLine("<H1>Bookmarks</H1>")

''''''''  Write Folder Content Start Tag''''''''''
MyFile.WriteLine("<DL><p>")

Dim myFolders

WriteDir(objFolder)

WriteFiles(objFolder)

''''''''  Write Folder Content End Tag''''''''''
MyFile.WriteLine("</DL><p>")

MyFile.Close

MsgBox "Export Complete." & vbCrLf & vbCrLf & "Your IE Favorites have been exported to 'bookmarks.html' on your Desktop."

Function WriteDir(objFolders)

	On Error Resume Next
	
	Set myFolders = objFolders.SubFolders

	Dim FolderObj
	
	For Each FolderObj in myFolders

		MyFile.WriteLine("<DT><H3>" & FolderObj.Name & "</H3>")
		''''''''  Write Folder Content Start Tag''''''''''
		MyFile.WriteLine("<DL><p>")
		''''''''  RECURSE''''''''''
		WriteDir(FolderObj)
		WriteFiles(FolderObj)
		''''''''  Write Folder Content End Tag''''''''''
		MyFile.WriteLine("</DL><p>")
		
	Next
	
End Function

Function WriteFiles(FolderObject)
	On Error Resume Next
	'''''''' Create a Collection of Files''''''''''
	Set colFiles = FolderObject.Files
	'MyFile.WriteLine("<DL><p>")
	For Each FileObj in colFiles
		MyFile.WriteLine("<DT><A HREF=""" & GetLinkURL(FileObj.Path) & """>" & Left(FileObj.Name, Len(FileObj.Name) - 4) & "</A>")
	Next
	'MyFile.WriteLine("</DL><p>")
End Function

Function GetLinkURL(filePath)
   	On Error Resume Next
   	Dim fileObject
   	Dim link, shellObject
 		
   	Set fileObject = CreateObject("Scripting.FileSystemObject")
   	Set shellObject = CreateObject("Wscript.Shell")
   	Set link = shellObject.CreateShortcut(filePath)
		
   	GetLinkURL = link.TargetPath

End function

Post Reply