将 Firefox 书签导出为单独的 .URL,同时保留时间戳

将 Firefox 书签导出为单独的 .URL,同时保留时间戳

我有大量 Firefox 书签,我想删除它们并将其存档为快捷方式文件 (.URL)。但我还想保留它们的添加日期,因为文件的上一次更改日期。

Firefox 使用一系列元数据来保存书签,例如添加日期上一次更改在单个 .json 文件中。

我需要做的是:

  1. 将 .json 文件中的书签导出为单独的 .URL
  2. 提取添加日期元数据并将其设置为 .URL 文件的最后修改日期

我不期望任何实用程序都具有此功能,因为它非常具体。但只要有效,我愿意尝试任何工具组合

答案1

创建 .URL 文件,同时保留来自任何浏览器的时间戳 bookmarks.html

此 VBA 宏可让您将标准 bookmarks.html 文件(Firefox、Chrome、Opera)转换为多个 .URL 文件(Internet Explorer)

作为奖励,它会读出创建日期从您的书签中删除并修改新的 .URL 文件以反映 Windows 资源管理器中的日期。它还保留您的文件夹和子文件夹结构。查看屏幕截图

在此处输入图片描述

用法

  • 启动所需的浏览器并将书签导出为HTML 文件.
    所有主流浏览器都支持该功能。
  • 下载并打开相应的版本
  • 使用漂亮的开始按钮
  • Excel 要求输入您在第一步中创建的 HTML 文件的路径
  • 所有新的快捷方式文件都存储在与 HTML 文件相同位置的新文件夹中
  • 文件创建文件已修改日期将更改为您在浏览器中首次创建书签时的相应日期

怎么运行的

  • VBA 宏以 unicode 格式将 HTML 文件作为纯文本打开(保留特殊字符)
  • 它逐行搜索“HREF=”并提取 URL
  • 它对添加日期以及用过的书签标题在您的浏览器中
  • 它会根据您的书签结构创建所有子文件夹
  • 它为每个书签创建一个新的文本文件,并将以下数据保存到该文件中
    [互联网快捷方式]
    URL=http://www.someaddress.com/
    
  • 文件保存为<bookmarktitle>.url
  • 标题被截断为最多 100 个字符,并且所有禁用字符均被删除
  • 检查快捷方式是否已存在,如果存在,则附加创建日期
  • 既定UNIX 日期转换成可读格式
  • 文件创建和文件修改的时间戳将更改为您在浏览器中保存书签的日期

有用的网址

答案2

如果你只想从任何浏览器创建快捷方式文件而不保留时间戳,那么这是最简单的方法

  1. 将书签导出为 HTML 文件。Internet
    Explorer、Firefox、Chrome 和 Opera 都内置了此功能
  2. 键入Win+R并输入%USERPROFILE%\Favorites
  3. 将所有内容临时备份到某处
  4. 打开 Internet Explorer → 文件 → 导入和导出 在此处输入图片描述
  5. 选择您的 HTML 文件并导入它们
  6. 键入Win+并再次R输入%USERPROFILE%\Favorites

现在,您已将所有书签作为纯 .URL 文件。您可以将它们移动到任何您想要的位置。Internet
Explorer 不会像其他浏览器那样(在单个文件中)存储书签。它只会为收藏夹文件夹中的每个书签创建 .URL 文件。

笔记:记得删除新的 IE 收藏夹,然后使用备份恢复它们

答案3

这是 nixda 2013 年的代码,经过编辑,纠正了一些拼写错误,并删除了在从 Google Chrome 导出的 html 文件中与超链接在同一行上找不到的上次修改日期。

修改了以下按钮单击脚本,注释掉最后修改的代码部分。

Private Sub CommandButton1_Click()
Dim shortcutfile As String
Dim myadddate As Double
forbidden = Array("\", "/", ":", "*", "?", """", "<", ">", "|", "&quot;", "&amp;", "&#39;")

    Application.ScreenUpdating = False
    ChDir ThisWorkbook.Path
    myfullfilename = Application.GetOpenFilename(fileFilter:="HTML Files, *.html")

    If myfullfilename = False Then Exit Sub
    mypath = Left$(myfullfilename, InStrRev(myfullfilename, "\")) & "InternetShortCuts" & " " & Format(Now, "yyyy.mm.dd hh-mm-ss")
    Workbooks.OpenText FileName:=myfullfilename, Origin:=-535, DataType:=xlDelimited, Tab:=False, semicolon:=False, comma:=False, Space:=False

    On Error Resume Next
    MkDir mypath
    On Error GoTo 0

    Set mysheet = ActiveWorkbook.Sheets(1)
    With mysheet
    For i = 1 To .UsedRange.SpecialCells(xlCellTypeLastCell).Row

        If InStr(UCase(.Cells(i, 1)), "<DT><H3 ADD_DATE=") <> 0 Then
            folderend = InStrRev(.Cells(i, 1), "<")
            folderstart = InStrRev(.Cells(i, 1), ">", folderend)
            newfolder = Mid(.Cells(i, 1), folderstart + 1, folderend - folderstart - 1)

            For j = 0 To UBound(forbidden)
                newfolder = Replace(newfolder, forbidden(j), "")
            Next j

            mypath = mypath & "\" & newfolder

            On Error Resume Next
            MkDir mypath
            On Error GoTo 0
        End If

        If InStr(UCase(.Cells(i, 1)), "</DL><P>") <> 0 Then
            mypath = Left(mypath, InStrRev(mypath, "\") - 1)
        End If

        If InStr(UCase(.Cells(i, 1)), "HREF=") <> 0 Then
            urlstart = InStr(.Cells(i, 1), "HREF=")
            urlend = InStr(.Cells(i, 1), "ADD_DATE=")
            myurl = Mid(.Cells(i, 1), urlstart + 6, urlend - urlstart - 8)

            'adddateend = InStr(.Cells(i, 1), "LAST_")
            'myadddate = Mid(.Cells(i, 1), urlend + 10, adddateend - urlend - 12)
            'myadddate = DateAdd("s", myadddate, DateSerial(1970, 1, 1))

            titleend = InStrRev(.Cells(i, 1), "<")
            titlestart = InStrRev(.Cells(i, 1), ">", titleend)
            mytitle = Mid(.Cells(i, 1), titlestart + 1, titleend - titlestart - 1)
            mytitle = Left(mytitle, 100)

            For j = 0 To UBound(forbidden)
                mytitle = Replace(mytitle, forbidden(j), "")
            Next j

            shortcutfile = mypath & "\" & Trim(mytitle) & ".url"

            With CreateObject("Scripting.FileSystemObject")
                'If .FileExists(shortcutfile) Then shortcutfile = mypath & "\" & Trim(mytitle) & " " & Format(myadddate, "yyyy.mm.dd hh-mm-ss") & ".url"
                If .FileExists(shortcutfile) Then shortcutfile = mypath & "\" & Trim(mytitle) & " " & ".url"
                With .CreateTextFile(shortcutfile, , True)
                    .write "[InternetShortcut]" & vbNewLine
                    .write "URL=" & myurl
                    .Close
                End With
            End With

            Call Settimestamp(shortcutfile, myadddate)

        End If
    Next i

    Close
    .Parent.Close False

    End With

    Application.ScreenUpdating = True
End Sub

修改了以下 change_timestamp 模块以纠正声明 CreateFileW 函数时的拼写错误,其中在 #VBA7 部分下将 lpFileName 声明为 LongLong 而不是 Long,以及在 #Else 部分下声明 CreateFileW 函数时的行延续。

Option Explicit

Private Const OPEN_EXISTING = &H3
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const GENERIC_WRITE = &H40000000

Public Type FileTime
    dwLowDateTime As Long
    dwHighDateTime As Long
End Type

Public Type SYSTEMTIME
    wYear As Integer
    wMonth As Integer
    wDayOfWeek As Integer
    wDay As Integer
    wHour As Integer
    wMinute As Integer
    wSecond As Integer
    wMilliseconds As Integer
End Type

#If VBA7 Then
    Private Declare PtrSafe Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime As FileTime, lpFileTime As FileTime) As Long
    Private Declare PtrSafe Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FileTime) As Long
    Private Declare PtrSafe Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

    Private Declare PtrSafe Function CreateFileW Lib "kernel32.dll" _
        (ByVal lpFileName As Long, _
        ByVal dwDesiredAccess As Long, _
        ByVal dwShareMode As Long, _
        ByVal lpSecurityAttributes As Long, _
        ByVal dwCreationDisposition As Long, _
        ByVal dwFlagsAndAttributes As Long, _
        ByVal hTemplateFile As Long) As Long

    Private Declare PtrSafe Function SetFileTimeCreate Lib "kernel32" Alias "SetFileTime" _
       (ByVal hFile As Long, _
        CreateTime As FileTime, _
        ByVal LastAccessTime As Long, _
        LastModified As FileTime) As Long
#Else
    Private Declare Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime As FileTime, lpFileTime As FileTime) As Long
    Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FileTime) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

    Private Declare Function CreateFileW Lib "kernel32.dll" _
        (ByVal lpFileName As Long, _
        ByVal dwDesiredAccess As Long, _
        ByVal dwShareMode As Long, _
        ByVal lpSecurityAttributes As Long, _
        ByVal dwCreationDisposition As Long, _
        ByVal dwFlagsAndAttributes As Long, _
        ByVal hTemplateFile As Long) As Long

    Private Declare Function SetFileTimeCreate Lib "kernel32" Alias "SetFileTime" _
       (ByVal hFile As Long, _
        CreateTime As FileTime, _
        ByVal LastAccessTime As Long, _
        LastModified As FileTime) As Long
#End If

'=======================================================================================================================
'=======================================================================================================================
'=======================================================================================================================

Function Settimestamp(FileName, FileDateTime)

Dim FileHandle As Long
Dim Res As Long
Dim ErrNum As Long
Dim ErrText As String
Dim tFileTime As FileTime
Dim tLocalTime As FileTime
Dim tSystemTime As SYSTEMTIME

With tSystemTime
    .wYear = Year(FileDateTime)
    .wMonth = Month(FileDateTime)
    .wDay = Day(FileDateTime)
    .wDayOfWeek = Weekday(FileDateTime) - 1
    .wHour = Hour(FileDateTime)
    .wMinute = Minute(FileDateTime)
    .wSecond = Second(FileDateTime)
End With

Res = SystemTimeToFileTime(lpSystemTime:=tSystemTime, lpFileTime:=tLocalTime)
Res = LocalFileTimeToFileTime(lpLocalFileTime:=tLocalTime, lpFileTime:=tFileTime)

FileHandle = CreateFileW(lpFileName:=StrPtr(FileName), _
                        dwDesiredAccess:=GENERIC_WRITE, _
                        dwShareMode:=FILE_SHARE_READ Or FILE_SHARE_WRITE, _
                        lpSecurityAttributes:=ByVal 0&, _
                        dwCreationDisposition:=OPEN_EXISTING, _
                        dwFlagsAndAttributes:=0, _
                        hTemplateFile:=0)

Res = SetFileTimeCreate( _
            hFile:=FileHandle, _
            CreateTime:=tFileTime, _
            LastAccessTime:=0&, _
            LastModified:=tFileTime)

CloseHandle FileHandle

End Function

相关内容