Delphi แตก Zip ด้วย TZip

สมัยก่อนเวลาจะเขียนโปรแกรมแตกไฟล์นั้นต้องไปหา component จำพวก Zip Forge หรือ Abbrevia สมัยนี้ง่ายขึ้นเยอะเพราะ ใน Delphi Version ใหม่ๆ มีตัวช่วย ที่เกี่ยวกับเรื่องนี้มาให้เลย อย่าเสียเวลากันเลยครับ มาดูกันดีกว่า

https://docwiki.embarcadero.com/Libraries/Alexandria/en/System.Zip.TZipFile.Extract

ผมอ้างอิงจาก Wiki ของ Embarcadero.com พบว่าคำสั่งแสนจะสั้นครับ ก่อนอื่นเลยก็ทำหน้าตาโปรแกรมขึ้นมาก่อน ก็สร้างหน้าตาแบบบ้าน มีปุ่มเดียวพอ

สร้าง zip file สำหรับ Test

จัด code ลงไป

uses System.zip;
procedure TForm9.Button1Click(Sender: TObject);
var
zipFile :TZipFile;
filename : String;
begin
zipFile := TZipFile.Create;
try
filename := 'D:\Delphi XE 10.3 Projects\ZipExtract\Win32\Debug\ReadMe.zip';
if zipFile.IsValid(filename) then begin
zipFile.Open(filename, zmRead);
zipFile.ExtractAll('D:\Delphi XE 10.3 Projects\ZipExtract\Win32\Debug\');
end;
finally
zipFile.Free;
end;
end;

เมื่อเรากด Run ก็จะสามารถแตก zip ออกมาได้ ไฟล์ที่อยู่ข้างในออกมา

หากสนใจลองเข้าไปดูใน GitHub ได้ที่

https://github.com/piyanatn/TZip

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response

More from Piyanat Nimkhuntod