FileRead

Her tür dosyadan veri okur.

uint FileRead(
 int file_handle, // Dosya tanıtıcısı
 ... // Okunacak parametrelerin listesi
 );

Parametreler

file_handle

[in] FileOpen().

...

[in] Dosyadan okunacak virgülle ayrılmış parametre listesi. Her parametre referansla aktarılır. Parametre sayısı 256'yı aşmamalıdır. Değişkenler temel türlerden olmalıdır; diziler, yapılar, matrisler ve vektörlere izin verilmez.

Dönüş Değeri

Okunan değişken sayısı. Beklenenden daha az değişken okunursa, okuma hatası GetLastError() ile analiz edilebilir. CSV dosyasından okuma sırasında satır sonuna rastlanırsa okuma kesilir, ancak hata oluşturulmaz.

Not

FileRead, FileWrite fonksiyonunun karşılığıdır. Fonksiyon evrenseldir ve CSV, TXT veya BIN gibi her tür dosyadan okur.

FileRead, okunacak dizenin uzunluğu önceden bilinmediği için ikili dosyadan string türündeki verileri okuyamaz.

İkili dosyadan okurken her değişkene veri türüne karşılık gelen bayt sayısı okunur (char - 1, int - 4, long - 8, double - 8 vb.).

Metin dosyasından okurken satırın tamamı, satır sonu karakterleri hariç olmak üzere string türündeki değişkene satır sonuna kadar okunur.

CSV dosyasından okurken önce ilgili türün metin gösterimini içeren dizeler okunur, ardından dize dönüştürülür ve ilgili türdeki değişkene aktarılır (örnekler için bkz. FileReadNumber, FileReadBool, FileReadDateTime).

Örnek:

//+------------------------------------------------------------------+
//|                                                 TestFileRead.mq5 |
//|                                  Copyright 2026, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   uint     written,read;
//--- farklı türlerden 13 değişken
   bool     bool_value=true;
   char     char_value=123;
   short    short_value=12345;  
   int      int_value=1234567;
   long     long_value=5000000000;
   float    float_value=FLT_EPSILON;
   double   double_value=M_PI;
   color    color1_value=clrAquamarine;
   color    color2_value=C'111,0,222';
   datetime datetime_value=TimeCurrent();
   complex  complex_value=1.1+0.1i;
   complexf complexf_value=5.5+0.5i;
   string   string_value="the quick brown fox jumps over the lazy dog";
//--- yazma için bir CSV dosyası aç
   int file_handle=FileOpen("test.csv",FILE_CSV|FILE_WRITE|FILE_ANSI);
//--- farklı türlerden 13 değişken yaz
   written=FileWrite(file_handle,bool_value,char_value,short_value,int_value,long_value,float_value,double_value,color1_value,color2_value,datetime_value,string_value,complex_value,complexf_value);
   bool_value=false;
   char_value=124;
   short_value=12347;  
   int_value=1234569;
   long_value=5001000000;
//--- CSV dosyasının ikinci satırına 13 değişken yaz
   written+=FileWrite(file_handle,bool_value,char_value,short_value,int_value,long_value,float_value,double_value,color1_value,color2_value,datetime_value,string_value,complex_value,complexf_value);
   bool_value=false;
   char_value=125;
   short_value=12349;  
   int_value=1234571;
   long_value=5002000000;
//--- CSV dosyasının üçüncü satırına 13 değişken yaz
   written+=FileWrite(file_handle,bool_value,char_value,short_value,int_value,long_value,float_value,double_value,color1_value,color2_value,datetime_value,string_value,complex_value,complexf_value);
   FileClose(file_handle);
   Print(written," bytes written");
   bool     bool_value2;
   char     char_value2;
   short    short_value2;  
   int      int_value2;
   long     long_value2;
   float    float_value2;
   double   double_value2;
   color    color1_value2;
   color    color2_value2;
   datetime datetime_value2;
   complex  complex_value2;
   complexf complexf_value2;
   string   string_value2;
   string   string2_value="untouched string";
//--- yazılan CSV dosyasını okuma için aç
   file_handle=FileOpen("test.csv",FILE_CSV|FILE_READ|FILE_ANSI);
//--- satırda bulunandan 1 değişken daha fazla okumayı dene
   read=FileRead(file_handle,bool_value2,char_value2,short_value2,int_value2,long_value2,float_value2,double_value2,color1_value2,color2_value2,datetime_value2,string_value2,complex_value2,complexf_value2,string2_value);
   FileClose(file_handle);
   Print("read ",read," variables");
   Print(bool_value2," ",char_value2," ",short_value2," ",int_value2," ",long_value2," ",float_value2," ",double_value2," ",color1_value2," ",color2_value2," ",datetime_value2," ",string_value2," ",complex_value2," ",complexf_value2," ",string2_value);
   string txt_line1,txt_line2,txt_line3;
//--- yazılan dosyayı metin dosyası olarak aç
   file_handle=FileOpen("test.csv",FILE_TXT|FILE_READ|FILE_ANSI);
//--- metin dosyasından 3 satır oku
   read=FileRead(file_handle,txt_line1,txt_line2,txt_line3);
   Print("\nread ",read," lines");
   FileClose(file_handle);
//--- bunların yazılan satırlar olduğunu görsel olarak kontrol et
   Print(txt_line1);
   Print(txt_line2);
   Print(txt_line3);
//--- yazma için ikili dosya aç
   file_handle=FileOpen("test.bin",FILE_BIN|FILE_WRITE);
//--- string hariç farklı türlerden 12 değişken yaz
   written=FileWrite(file_handle,bool_value,char_value,short_value,int_value,long_value,float_value,double_value,color1_value,color2_value,datetime_value,complex_value,complexf_value);
   FileClose(file_handle);
   Print("");
   Print(written," bytes written");
   bool     bool_value3;
   char     char_value3;
   short    short_value3;  
   int      int_value3;
   long     long_value3;
   float    float_value3;
   double   double_value3;
   color    color1_value3;
   color    color3_value3;
   datetime datetime_value3;
   complex  complex_value3;
   complexf complexf_value3;
//--- yazılan ikili dosyayı okuma için aç
   file_handle=FileOpen("test.bin",FILE_BIN|FILE_READ);
//--- aynı türlerden 12 değişken oku
   read=FileRead(file_handle,bool_value3,char_value3,short_value3,int_value3,long_value3,float_value3,double_value3,color1_value3,color3_value3,datetime_value3,complex_value3,complexf_value3);
   FileClose(file_handle);
   Print("read ",read," variables");
//--- verilerin doğru okunduğunu görsel olarak kontrol et
   Print(bool_value3," ",char_value3," ",short_value3," ",int_value3," ",long_value3," ",float_value3," ",double_value3," ",color1_value3," ",color3_value3," ",datetime_value3," ",complex_value3," ",complexf_value3);
  }

Experts günlüğündeki çıktı

554 bytes written
read 13 variables
true 123 12345 1234567 5000000000 1.1920928955078125e-07 3.141592653589793 clrAquamarine 111,0,222 2026.09.25 14:44:25 the quick brown fox jumps over the lazy dog (1.1,0.1) (5.5,0.5) untouched string
 
read 3 lines
true 123 12345 1234567 5000000000 1.1920928955078125e-07 3.141592653589793 clrAquamarine 111,0,222 2026.09.25 14:44:25 the quick brown fox jumps over the lazy dog (1.1,0.1) (5.5,0.5)
false 124 12347 1234569 5001000000 1.1920928955078125e-07 3.141592653589793 clrAquamarine 111,0,222 2026.09.25 14:44:25 the quick brown fox jumps over the lazy dog (1.1,0.1) (5.5,0.5)
false 125 12349 1234571 5002000000 1.1920928955078125e-07 3.141592653589793 clrAquamarine 111,0,222 2026.09.25 14:44:25 the quick brown fox jumps over the lazy dog (1.1,0.1) (5.5,0.5)
 
68 bytes written
read 12 variables
false 125 12349 1234571 5002000000 1.1920928955078125e-07 3.141592653589793 clrAquamarine 111,0,222 2026.09.25 14:44:25 (1.1,0.1) (5.5,0.5)

Ayrıca Bakınız

FileWrite, FileReadNumber, FileReadBool, FileReadDateTime