-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathextractBookmarks.vbs
34 lines (33 loc) · 1.43 KB
/
extractBookmarks.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Const ForReading = 1, ForWriting = 2, ForAppending = 8, CreateIfNeeded = true
Set objFSO = CreateObject("Scripting.FileSystemObject")
bookmarkfile = "bookmarks-joined.html"
Set bookmarks = objFSO.OpenTextFile(bookmarkfile, ForReading)
Set regEx = New RegExp
regEx.Global = True
regex.ignorecase = True
Set regEx2 = New RegExp
regEx2.Global = True
regEx2.Pattern = "[^a-zA-Z0-9-_. ]"
dim fso, fullPathToBookmarkFile
set fso = CreateObject("Scripting.FileSystemObject")
fullPathToBookmarkFile = fso.GetAbsolutePathName(bookmarkfile)
outpath = Replace(fullPathToBookmarkFile,"\bookmarks-joined.html","\bookmarks")
regEx.Pattern = "<DT><A HREF=""(.*)"" ADD_DATE.*>(.*)</A>"
do until bookmarks.AtEndOfStream
line = bookmarks.readline()
if regEx.test(line) then
shortcut = regEx.Replace(line,"$1")
filename = trim(regEx.Replace(line,"$2"))
filename = Regex2.Replace(filename, "_")
filename = outpath & "\" & left(filename, 80) & ".url"
'wscript.echo filename -- 03/20/2021 JT: commenting out to prevent dialogs from running to speed things up
'the following skips invalid filenames, you should add a routine to filter out invalid filename characters in your codeset
on error resume next
Set objFile = objFSO.OpenTextFile(filename, ForWriting, CreateIfNeeded)
if err.number <> 0 then
wscript.echo err.description
end if
objFile.write "[InternetShortcut]" & vbcrlf & "URL=" & shortcut
objFile.close
end if
loop