我出一个题目 关于文件处理的偏实际应用的 不限语言
要求处理Sumatra PDF的配置文件 删除其中不存在文件的缓存数据 例子文件如下
# For documentation, see http://blog.kowalczyk.info/software/sumatrapdf/settings3.0.html
MainWindowBackground = #80fff200
EscToExit = false
ReuseInstance = false
UseSysColors = false
FixedPageUI [
TextColor = #000000
BackgroundColor = #ffffff
SelectionColor = #f5fc0c
WindowMargin = 2 4 2 4
PageSpacing = 4 4
]
EbookUI [
FontName = Georgia
FontSize = 12.5
TextColor = #5f4b32
BackgroundColor = #fbf0d9
UseFixedPageUI = false
]
ComicBookUI [
WindowMargin = 0 0 0 0
PageSpacing = 4 4
CbxMangaMode = false
]
ChmUI [
UseFixedPageUI = false
]
ExternalViewers [
]
ShowMenubar = true
ReloadModifiedDocuments = true
FullPathInTitle = false
ZoomLevels = 8.33 12.5 18 25 33.33 50 66.67 75 100 125 150 200 300 400 600 800 1000 1200 1600 2000 2400 3200 4800 6400
ZoomIncrement = 0
PrinterDefaults [
PrintScale = shrink
PrintAsImage = false
]
ForwardSearch [
HighlightOffset = 0
HighlightWidth = 15
HighlightColor = #6581ff
HighlightPermanent = false
]
CustomScreenDPI = 0
RememberStatePerDocument = true
UiLanguage = cn
ShowToolbar = true
ShowFavorites = false
AssociateSilently = false
CheckForUpdates = true
RememberOpenedFiles = true
EnableTeXEnhancements = false
DefaultDisplayMode = automatic
DefaultZoom = fit page
WindowState = 2
WindowPos = 560 0 799 1034
ShowToc = true
SidebarDx = 483
TocDy = 0
ShowStartPage = true
UseTabs = true
FileStates [
[
FilePath = Z:\论道德建设的实践性原则_杜杰.pdf
Favorites [
]
IsPinned = false
IsMissing = false
OpenCount = 0
UseDefaultState = false
DisplayMode = continuous
ScrollPos = -1 182
PageNo = 2
Zoom = 200
Rotation = 0
WindowState = 2
WindowPos = 560 0 799 1034
ShowToc = false
SidebarDx = 483
DisplayR2L = false
ReparseIdx = 0
]
[
FilePath = Z:\1-s2.0-096808969500053J-main.pdf
Favorites [
]
IsPinned = false
IsMissing = false
OpenCount = 1
UseDefaultState = false
DisplayMode = continuous
ScrollPos = -1 414
PageNo = 1
Zoom = 200
Rotation = 0
WindowState = 2
WindowPos = 560 0 799 1034
ShowToc = false
SidebarDx = 483
DisplayR2L = false
ReparseIdx = 0
TocState = 2 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 21 23 24 25 27 28 30 31 32 33 34 35 36 37 38 39 40
]
]
TimeOfLastUpdateCheck = 30414503 -647654859
OpenCountWeek = 206
MainWindowBackground = #80fff200
EscToExit = false
ReuseInstance = false
UseSysColors = false
FixedPageUI [
TextColor = #000000
BackgroundColor = #ffffff
SelectionColor = #f5fc0c
WindowMargin = 2 4 2 4
PageSpacing = 4 4
]
EbookUI [
FontName = Georgia
FontSize = 12.5
TextColor = #5f4b32
BackgroundColor = #fbf0d9
UseFixedPageUI = false
]
ComicBookUI [
WindowMargin = 0 0 0 0
PageSpacing = 4 4
CbxMangaMode = false
]
ChmUI [
UseFixedPageUI = false
]
ExternalViewers [
]
ShowMenubar = true
ReloadModifiedDocuments = true
FullPathInTitle = false
ZoomLevels = 8.33 12.5 18 25 33.33 50 66.67 75 100 125 150 200 300 400 600 800 1000 1200 1600 2000 2400 3200 4800 6400
ZoomIncrement = 0
PrinterDefaults [
PrintScale = shrink
PrintAsImage = false
]
ForwardSearch [
HighlightOffset = 0
HighlightWidth = 15
HighlightColor = #6581ff
HighlightPermanent = false
]
CustomScreenDPI = 0
RememberStatePerDocument = true
UiLanguage = cn
ShowToolbar = true
ShowFavorites = false
AssociateSilently = false
CheckForUpdates = true
RememberOpenedFiles = true
EnableTeXEnhancements = false
DefaultDisplayMode = automatic
DefaultZoom = fit page
WindowState = 2
WindowPos = 560 0 799 1034
ShowToc = true
SidebarDx = 483
TocDy = 0
ShowStartPage = true
UseTabs = true
FileStates [
[
FilePath = Z:\论道德建设的实践性原则_杜杰.pdf
Favorites [
]
IsPinned = false
IsMissing = false
OpenCount = 0
UseDefaultState = false
DisplayMode = continuous
ScrollPos = -1 182
PageNo = 2
Zoom = 200
Rotation = 0
WindowState = 2
WindowPos = 560 0 799 1034
ShowToc = false
SidebarDx = 483
DisplayR2L = false
ReparseIdx = 0
]
[
FilePath = Z:\1-s2.0-096808969500053J-main.pdf
Favorites [
]
IsPinned = false
IsMissing = false
OpenCount = 1
UseDefaultState = false
DisplayMode = continuous
ScrollPos = -1 414
PageNo = 1
Zoom = 200
Rotation = 0
WindowState = 2
WindowPos = 560 0 799 1034
ShowToc = false
SidebarDx = 483
DisplayR2L = false
ReparseIdx = 0
TocState = 2 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 21 23 24 25 27 28 30 31 32 33 34 35 36 37 38 39 40
]
]
TimeOfLastUpdateCheck = 30414503 -647654859
OpenCountWeek = 206
比如第一个文件已经不存在的 则在新文件里面将
[
FilePath = Z:\论道德建设的实践性原则_杜杰.pdf
Favorites [
...
]
FilePath = Z:\论道德建设的实践性原则_杜杰.pdf
Favorites [
...
]
这些全部删除 生成一个新的文件
我用Emacs Lisp写了一个 想看看各位如何实现的
程序代码:
(with-temp-buffer (insert-file-contents "Z:/a.txt") (while (re-search-forward "^.*FilePath = \\(.*\\.pdf\\)$" nil t) (let ((filename (replace-regexp-in-string "\\\\" "/" (match-string 1) t t)) (p1) (p2)) (unless (file-exists-p filename) (beginning-of-line) (previous-line) (setq p1 (point)) (forward-sexp) (setq p2 (point)) (delete-region p1 p2) (kill-line) )) ) (write-file "Z:/output.txt"))