1. 首頁
  2. 幫助中心
  3. 使用者手冊
  4. 過濾器 Filters

使用者手冊 · 過濾器(Filters)

本章詳細說明 GoodSync 的 Job 過濾器系統 — 包含/排除規則、萬用字元、按路徑/名稱/大小/時間/屬性匹配的完整語法、any/all 限定符與過濾器組合規則。

概述

預設情況下,GoodSync 同步所有非隱藏、非系統的檔案與資料夾。如果關閉排除選項,隱藏與系統檔案也可被同步。

檢視與配置 Filters:使用 Job → Options 選單項,或右鍵 Job 選擇「Options」,切換到「Filters」標籤頁。

Exclude Filters(排除過濾器,預設為空)

名稱匹配 Exclude Filter 的檔案或資料夾將被排除在同步之外。

例如:通常會排除目標檔案 *.OBJ 與編輯器備份檔案 *.BAK

NOTE:按設計,Exclusion 優先於 Inclusion。

Include Filters(包含過濾器,預設為空)

名稱匹配 Inclusion Filter — 且不匹配任何 Exclusion Filter — 的檔案與資料夾將被包含在同步中。

Include Filters 會先於 Exclude Filters 應用。無任何行的 Include Filter 等同於包含所有內容(即被忽略)。

從 Analyze 後的右鍵選單新增 Filter

排除或包含檔案/一組檔案的最簡便方式:執行 Analyze 後右鍵檔案或資料夾,選擇以下命令之一:

  • Exclude "/FolderName/FileName" file or folder — 僅排除該檔案或資料夾(按其完整路徑)。
  • Exclude All "ItemName" files or folders — 排除任何子資料夾中所有名為 ItemName 的檔案或資料夾。
  • Exclude All "*.ext" files — 排除所有子資料夾中副檔名為 ext 的檔案。
  • Include Only "/FolderName/FileName" file or folder — 僅包含該檔案或資料夾(按其完整路徑)。
  • Include Only "*.ext" files — 包含所有子資料夾中副檔名為 ext 的檔案。

這些命令會向 Jobs → Options → Filters 中的 Exclusions/Inclusions 列表新增一行。

預設 Exclude Filter 選項

提供一組帶勾選框的預設 Exclude Filter 選項,可一鍵啟用或禁用:

  • Exclude empty folders(預設未勾選)— 若勾選,排除空資料夾或僅含空資料夾的資料夾。資料夾被視為空:不含任何檔案、或僅含被 Filters 排除的檔案。
  • Exclude Hidden files and folders(預設勾選)— 排除帶「Hidden」屬性的檔案與資料夾。
  • Exclude System files and folders(預設勾選)— 排除帶「System」屬性的檔案與資料夾。
  • Exclude Temporary files and folders(預設勾選,僅 Windows)— 排除不值得儲存的臨時檔案與資料夾。

複製與貼上 Filters

使用「Copy All」與「Paste」按鈕可在 Include 與 Exclude 之間,以及不同 Job 之間複製貼上 Filters。

Filter 語法與引數

萬用字元(Wildcards)

  • * — 匹配任意字元序列。
  • ? — 匹配任意單個字元。
  • [a-z] — 匹配字元範圍(如 a 到 z)。
  • \c — 匹配字元 c — 當要匹配的字元是 *?[ 時使用。
  • / — 資料夾分隔符(不要使用 \,即便在 Windows 上也不行)。

path / name 匹配

path /folder/file — 以「path /」(或僅「/」)開頭的行 — 把檔案或資料夾的路徑(相對於同步資料夾)與指定萬用字元或字串匹配。

示例:

path /folder1/file2.ext     - 按路徑匹配檔案
path /Parent*               - 頂級資料夾為 "Parent" 的所有路徑
path /[a-z0-9]*             - 頂級資料夾以 a-z 或 0-9 開頭的所有路徑
path /\[Originals\]         - 頂級資料夾為 "[Originals]" 的所有路徑

NOTE:Include Filter path /folder 僅包含 /folder 本身,不包含其內的檔案。要包含該資料夾內的檔案,寫為 path /folder/*

name filename/foldername — 以「name」開頭的行 — 把檔案或資料夾名稱(路徑的最後一段)與指定萬用字元或字串匹配。

示例:

name *.xls               - Excel 檔案
name *kiss*              - 名稱含 "kiss" 的檔案或資料夾
name *.???               - 三字元副檔名的所有檔案與資料夾
name *.[a-z][a-z][a-z]   - 三字母副檔名的所有檔案與資料夾
name \[Originals\]       - 名稱為 "[Originals]" 的所有檔案與資料夾

size 匹配(按檔案大小)

以「any size」或「all size」開頭的行允許按檔案大小排除/包含檔案:

any size<N      意為  size.left<N OR size.right<N
all size<N      意為  size.left<N AND size.right<N
any size>N      意為  size.left>N OR size.right>N
all size>N      意為  size.left>N AND size.right>N
any size=N      意為  size.left=N OR size.right=N
all size=N      意為  size.left=N AND size.right=N
any size!=N     意為  size.left!=N OR size.right!=N
all size!=N     意為  size.left!=N AND size.right!=N
any size>=N     意為  size.left>=N OR size.right>=N
all size>=N     意為  size.left>=N AND size.right>=N
any size<=N     意為  size.left<=N OR size.right<=N
all size<=N     意為  size.left<=N AND size.right<=N
any size[S1,S2] 意為  S1 <= size.left < S2 OR  S1 <= size.right < S2
all size[S1,S2] 意為  S1 <= size.left < S2 AND S1 <= size.right < S2

大小常量可以是位元組數,或帶字尾:

  • K = 千位元組
  • M = 兆位元組

「size」匹配行中不允許有空格。非檔案項(資料夾、連結、已刪除或不存在的檔案)在 size 比較中視為大小 0。

示例:

all size>=100   - 兩側均≥100 位元組的檔案
any size<2K     - 兩側任一邊大小<2,048 位元組(1K=1024)的檔案,連結與已刪除檔案也算
all size=3M     - 兩側均恰好為 3,145,728 位元組(1M=1024×1024)的檔案

time 匹配(按修改時間)

以「any time」或「all time」開頭的行允許按修改時間排除/包含檔案:

any time<T       意為  time.left<T OR time.right<T
all time<T       意為  time.left<T AND time.right<T
any time>T       意為  time.left>T OR time.right>T
all time>T       意為  time.left>T AND time.right>T
any time=T       意為  time.left=T OR time.right=T
all time=T       意為  time.left=T AND time.right=T
any time!=T      意為  time.left!=T OR time.right!=T
all time!=T      意為  time.left!=T AND time.right!=T
any time>=T      意為  time.left>=T OR time.right>=T
all time>=T      意為  time.left>=T AND time.right>=T
any time<=T      意為  time.left<=T OR time.right<=T
all time<=T      意為  time.left<=T AND time.right<=T
any time[S1,S2]  意為  S1 <= time.left <= S2 OR  S1 <= time.right <= S2
all time[S1,S2]  意為  S1 <= time.left <= S2 AND S1 <= time.right <= S2

其中 T 是日期,可使用以下格式:

  • YYYY/MM/DD — 年/月/日
  • -Nd — N 天前
  • +Nd — N 天後
  • -Nh — N 小時前
  • +Nh — N 小時後
  • -Nm — N 分鐘前
  • +Nm — N 分鐘後

「time」匹配行中不允許有空格。僅已存在(未刪除)的檔案參與 time 比較。非檔案物件(資料夾、連結、已刪除檔案)的修改時間視為 NullTime(1970 年 1 月 1 日)。

示例:

any time>=2008/7/4  - 任一側在 2008-07-04 00:00 或之後修改的檔案
all time<-5d        - 兩側均早於 5 天前的檔案
time>=+7d           - 任一側 7 天後或更晚修改的檔案

is / exist 謂詞

以「is」開頭的行匹配檔案與資料夾的屬性:

  • isfolder — 匹配資料夾
  • isfile — 匹配檔案
  • issymlink — 匹配符號連結或 Junction
  • ishidden — 匹配帶 hidden 屬性的檔案與資料夾
  • issystem — 匹配帶 system 屬性的檔案與資料夾(僅 Windows)
  • isarchive — 匹配帶 archive 屬性的檔案與資料夾(僅 Windows)
  • isreadonly — 匹配帶只讀屬性的檔案與資料夾(僅 Windows)
  • isoffline — 匹配帶 offline 屬性的檔案與資料夾(僅 Windows)
  • iscompressed — 匹配帶 compressed 屬性的檔案與資料夾(僅 Windows)
  • isencrypted — 匹配帶 encrypted 屬性的檔案與資料夾(僅 Windows,EFS 加密)

以「exist」開頭的行匹配檔案/資料夾的存在與否事實:

  • existboth — 檔案或資料夾在左右兩側都存在
  • existany — 檔案或資料夾在左側、右側或兩側存在
  • existone — 檔案或資料夾僅在一側存在

any / all 限定符

當左右兩側的檔案修改時間不同時,必須使用「any」或「all」限定符以達到預期結果。

例:Exclude Filter time<-30d 對所有「left time < tNow - 30d 或 right time < tNow - 30d」的檔案均為真。

因此,如果目標是排除兩側都早於 30 天的檔案,應使用 all time<-30d — 等價於「left time < tNow - 30d AND right time < tNow - 30d」。

Filter 組合(Filter composition)

Filters 各行之間存在隱式 OR

每行可包含多個用分號「;」分隔的子句 — 同一行的子句之間存在隱式 AND

示例:

ishidden; name *.bak; all time <-60d
all size<1k

該 Filter 匹配「帶 .BAK 副檔名、且兩側都早於 60 天的隱藏檔案」「兩側大小均<1024 位元組的檔案」。

如果同時指定 Exclude 與 Include Filters,會先用 Include 過濾,再對其結果應用 Exclude。

更具體地說,對於:

Exclude Filter:
  ExcludeLine1
  ExcludeLine2
  ExcludeLine3

Include Filter:
  IncludeLine1
  IncludeLine2
  IncludeLine3

計算結果為:

(IncludeLine1 OR IncludeLine2 OR IncludeLine3) AND
NOT (ExcludeLine1 OR ExcludeLine2 OR ExcludeLine3)

僅絕對路徑匹配(Absolute Paths Only match)

如果 Include Filter 中所有行都是絕對路徑匹配/folderpath /folder),將應用「僅絕對路徑匹配」 — 僅與 Filter 行匹配的路徑會被包含。

如果 Include Filter 中存在任何非路徑匹配name 模式time -Ndsize N 等),則所有資料夾都被包含在匹配中 — 以便其內檔案可被非路徑過濾器匹配。