פיצול ומזוג קובצי PST
Contents
[
Hide
]
API של Aspose.Email מאפשרת לפצל קובץ PST יחיד למספר קבצי PST בגודל קובץ הרצוי. ניתן גם למזג מספר קבצי PST לקובץ PST יחיד. הן פעולת הפיצול והן פעולת המיזוג של PST ניתנות למעקב על‑ידי הוספת אירועים לפעולות אלו.
נסו זאת!
מזג ושלב קבצי אימייל מרובים באופן מקוון עם גרסת החינם Aspose.Email Merger App.
פיצול קבצי PST
פיצול למספר קובצי PST
קטע הקוד הבא מראה כיצד לפצל קובץ אחסון למספר קבצים:
import os
from aspose.email.storage.pst import PersonalStorage
data_dir = "DataDir_Outlook"
dst_split = os.path.join(data_dir, "Chunks")
# Delete the files if already present
for file in os.listdir(dst_split):
file_path = os.path.join(dst_split, file)
if os.path.isfile(file_path):
os.remove(file_path)
pst_file = os.path.join(data_dir, "pst.pst")
try:
with PersonalStorage.from_file(pst_file) as personal_storage:
# Splits into PST chunks with a size of 5MB
personal_storage.split_into(5000000, dst_split)
except Exception as ex:
print(str(ex))
print("This example will only work if you apply a valid Aspose.Email License. "
"You can purchase a full license or get a 30-day"
" temporary license from http://www.aspose.com/purchase/default.aspx.")
פיצול לפי קריטריון ספציפי
קטע הקוד הבא מראה כיצד לפצל קובץ אחסון לפי קריטריון מסוים:
import os
from datetime import datetime
from aspose.email.tools.search import MailQueryBuilder
from aspose.email.storage.pst import PersonalStorage
data_dir = "DataDir_Outlook"
path_to_pst = os.path.join(data_dir, "pathToPst")
pst_file = os.path.join(data_dir, "PersonalStorage_New.pst")
# Define search criteria
builder = MailQueryBuilder()
builder.sent_date.since(datetime(2005, 4, 1))
builder.sent_date.before(datetime(2005, 4, 7))
query = builder.get_query()
# Delete existing PST files if any
if os.path.exists(path_to_pst):
for file in os.listdir(path_to_pst):
file_path = os.path.join(path_to_pst, file)
if os.path.isfile(file_path) and file.endswith(".pst"):
os.remove(file_path)
# Split Personal Storage into multiple PST files based on criteria
with PersonalStorage.from_file(pst_file) as personal_storage:
personal_storage.split_into(query, path_to_pst)
מיזוג קבצי PST
מיזוג לקובץ PST יחיד
קטע הקוד הבא מראה כיצד למזג קבצי אחסון מרובים לקובץ אחד:
import os
from aspose.email.storage.pst import PersonalStorage
data_dir = "DataDir_Outlook"
sub_pst = os.path.join(data_dir, "Sub.pst")
merge_folder = os.path.join(data_dir, "MergePST")
total_added = 0
try:
with PersonalStorage.from_file(sub_pst) as personal_storage:
# Merge with the PST files located in the separate folder.
personal_storage.merge_with(os.path.join(merge_folder, "*"))
print("Total messages added:", total_added)
print("\nPST merged successfully at", sub_pst)
except Exception as ex:
print(ex)
print("This example will only work if you apply a valid Aspose Email License. "
"You can purchase a full license or get a 30-day temporary license "
"from http://www.aspose.com/purchase/default.aspx.")
מיזוג תיקיות מקובץ PST אחר
קטע הקוד הבא מראה כיצד למזג תיקיות מקובץ PST אחר:
from aspose.email.storage.pst import PersonalStorage, StandardIpmFolder
data_dir = "DataDir_Outlook\\"
destination_pst = PersonalStorage.from_file(data_dir + "destination.pst")
source_pst = PersonalStorage.from_file(data_dir + "source.pst")
total_added = 0
try:
with destination_pst, source_pst:
destination_folder = destination_pst.root_folder.add_sub_folder("FolderFromAnotherPst")
source_folder = source_pst.get_predefined_folder(StandardIpmFolder.DELETED_ITEMS)
# Merge with the folder from another PST.
destination_folder.merge_with(source_folder)
print("Total messages added:", total_added)
except Exception as ex:
print(ex)
print("This example will only work if you apply a valid Aspose Email License. "
"You can purchase a full license or get a 30-day temporary license "
"from http://www.aspose.com/purchase/default.aspx.")