unit WinForm1;

interface

uses
  System.Drawing, System.Collections, System.ComponentModel,
  System.Windows.Forms, System.Data, System.IO, System.Management;

type
  TWinForm1 = class(System.Windows.Forms.Form)
  {$REGION 'Designer Managed Code'}
  strict private
    /// <summary>
    /// Required designer variable.
    /// </summary>
    Components: System.ComponentModel.Container;
    TextBox1: System.Windows.Forms.TextBox;
    Button1: System.Windows.Forms.Button;
    TextBox2: System.Windows.Forms.TextBox;
    Button2: System.Windows.Forms.Button;
    Button3: System.Windows.Forms.Button;
    Label1: System.Windows.Forms.Label;
    Label2: System.Windows.Forms.Label;
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    procedure InitializeComponent;
    procedure Button1_Click(sender: System.Object; e: System.EventArgs);
    procedure Button2_Click(sender: System.Object; e: System.EventArgs);
    procedure Button3_Click(sender: System.Object; e: System.EventArgs);
  {$ENDREGION}
  strict protected
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    procedure Dispose(Disposing: Boolean); override;

  private
  function ZnajdzPlik(nazwaPliku,katalog: String):String;
    { Private Declarations }
  public
    constructor Create;
  end;

  [assembly: RuntimeRequiredAttribute(TypeOf(TWinForm1))]

implementation

{$AUTOBOX ON}

{$REGION 'Windows Form Designer generated code'}
/// <summary>
/// Required method for Designer support -- do not modify
/// the contents of this method with the code editor.
/// </summary>
procedure TWinForm1.InitializeComponent;
begin
  Self.TextBox1 := System.Windows.Forms.TextBox.Create;
  Self.Button1 := System.Windows.Forms.Button.Create;
  Self.TextBox2 := System.Windows.Forms.TextBox.Create;
  Self.Button2 := System.Windows.Forms.Button.Create;
  Self.Button3 := System.Windows.Forms.Button.Create;
  Self.Label1 := System.Windows.Forms.Label.Create;
  Self.Label2 := System.Windows.Forms.Label.Create;
  Self.SuspendLayout;
  // 
  // TextBox1
  // 
  Self.TextBox1.Location := System.Drawing.Point.Create(10, 24);
  Self.TextBox1.Name := 'TextBox1';
  Self.TextBox1.Size := System.Drawing.Size.Create(102, 22);
  Self.TextBox1.TabIndex := 0;
  Self.TextBox1.Text := 'CONFIG.SYS';
  // 
  // Button1
  // 
  Self.Button1.Location := System.Drawing.Point.Create(224, 24);
  Self.Button1.Name := 'Button1';
  Self.Button1.Size := System.Drawing.Size.Create(94, 26);
  Self.Button1.TabIndex := 1;
  Self.Button1.Text := 'Szukaj';
  Include(Self.Button1.Click, Self.Button1_Click);
  // 
  // TextBox2
  // 
  Self.TextBox2.Location := System.Drawing.Point.Create(120, 24);
  Self.TextBox2.Name := 'TextBox2';
  Self.TextBox2.Size := System.Drawing.Size.Create(96, 22);
  Self.TextBox2.TabIndex := 2;
  Self.TextBox2.Text := 'c:\';
  // 
  // Button2
  // 
  Self.Button2.Location := System.Drawing.Point.Create(8, 72);
  Self.Button2.Name := 'Button2';
  Self.Button2.Size := System.Drawing.Size.Create(310, 26);
  Self.Button2.TabIndex := 3;
  Self.Button2.Text := 'Informacje o pliku c:\CONFIG.SYS';
  Include(Self.Button2.Click, Self.Button2_Click);
  // 
  // Button3
  // 
  Self.Button3.Location := System.Drawing.Point.Create(8, 104);
  Self.Button3.Name := 'Button3';
  Self.Button3.Size := System.Drawing.Size.Create(310, 26);
  Self.Button3.TabIndex := 4;
  Self.Button3.Text := 'Ilość wolnego miejsca na dysku C:';
  Include(Self.Button3.Click, Self.Button3_Click);
  // 
  // Label1
  // 
  Self.Label1.Location := System.Drawing.Point.Create(8, 8);
  Self.Label1.Name := 'Label1';
  Self.Label1.TabIndex := 5;
  Self.Label1.Text := 'Nazwa pliku:';
  // 
  // Label2
  // 
  Self.Label2.Location := System.Drawing.Point.Create(120, 8);
  Self.Label2.Name := 'Label2';
  Self.Label2.TabIndex := 6;
  Self.Label2.Text := 'Katalog:';
  // 
  // TWinForm1
  // 
  Self.AutoScale := False;
  Self.AutoScaleBaseSize := System.Drawing.Size.Create(6, 15);
  Self.ClientSize := System.Drawing.Size.Create(328, 144);
  Self.Controls.Add(Self.Button3);
  Self.Controls.Add(Self.Button2);
  Self.Controls.Add(Self.TextBox2);
  Self.Controls.Add(Self.TextBox1);
  Self.Controls.Add(Self.Button1);
  Self.Controls.Add(Self.Label1);
  Self.Controls.Add(Self.Label2);
  Self.Name := 'TWinForm1';
  Self.Text := 'Pliki (Windows Forms)';
  Self.ResumeLayout(False);
end;
{$ENDREGION}
function TWinForm1.ZnajdzPlik(nazwaPliku,katalog: String):String;
var ListaPlikow: array of String;
    i: integer;
begin
try
  listaPlikow:=System.IO.Directory.GetFiles(katalog);
  for i:=0 to length(listaPlikow)-1 do
  begin
    if nazwaPliku.ToLower=System.IO.FileInfo.Create(listaPlikow[i]).get_Name.ToLower   then
      begin
      Result:='Znaleziono: '+listaPlikow[i];
      Exit;
      end
    else
      Result:='Nie znaleziono pliku: '+NazwaPliku;
  end;
except
  Result:='Niepoprawna nazwa katalogu';
end;
end;


procedure TWinForm1.Dispose(Disposing: Boolean);
begin
  if Disposing then
  begin
    if Components <> nil then
      Components.Dispose();
  end;
  inherited Dispose(Disposing);
end;

constructor TWinForm1.Create;
begin
  inherited Create;
  //
  // Required for Windows Form Designer support
  //
  InitializeComponent;
  //
  // TODO: Add any constructor code after InitializeComponent call
  //
end;

procedure TWinForm1.Button2_Click(sender: System.Object; e: System.EventArgs);
var plik: FileInfo;
    w: String;
begin
plik:=FileInfo.Create('c:\config.sys');
w:='Pełna nazwa pliku:  '+plik.FullName+#13;
w:=w+'Nazwa katalogu:  '+plik.DirectoryName+#13;
w:=w+'Nazwa pliku:  '+plik.Name+#13;
w:=w+'Rozszerzenie pliku:  '+plik.Extension+#13;
w:=w+'Symbol dysku:  '+plik.ToString.Remove(plik.ToString.IndexOf('\'),plik.ToString.Length-plik.ToString.IndexOf('\'))+#13;
MessageBox.Show(w);
end;

procedure TWinForm1.Button3_Click(sender: System.Object; e: System.EventArgs);
var m: ManagementObject;
    wolneMiejsce, wielkoscDysku: Double;
begin
m:= ManagementObject.Create('WIN32_LogicalDisk.DeviceID="c:"');
wolneMiejsce:=System.Convert.ToDouble(m['FreeSpace']) /1024/1024;
wielkoscDysku:=System.Convert.ToDouble(m['Size'])/1024/1024;
messagebox.Show('Wielkość dysku: '+wielkoscDysku.ToString+' MB'+#13+'Ilość wolnego miejsca na dysku: '+wolneMiejsce.ToString+'MB');
end;

procedure TWinForm1.Button1_Click(sender: System.Object; e: System.EventArgs);
begin
MessageBox.Show(ZnajdzPlik(TextBox1.Text,TextBox2.Text));
end;

end.
