Need some help in the code

 
Hi i m working on to save data in to any directory in csv format
//+------------------------------------------------------------------+
//|                                              File Read Write.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

// êîíñòàíòû äëÿ ôóíêöèè _lopen
#define OF_READ               0
#define OF_WRITE              1
#define OF_READWRITE          2
#define OF_SHARE_COMPAT       3
#define OF_SHARE_DENY_NONE    4
#define OF_SHARE_DENY_READ    5
#define OF_SHARE_DENY_WRITE   6
#define OF_SHARE_EXCLUSIVE    7

#import "kernel32.dll"
   int _lopen  (string path, int of);
   int _lcreat (string path, int attrib);
   int _llseek (int handle, int offset, int origin);
   int _lread  (int handle, string buffer, int bytes);
   int _lwrite (int handle, string buffer, int bytes);
   int _lclose (int handle);
#import


int init(){

 return(0);
}

int start()
  {
//----
    string buffer=ReadFile("C:\\Test.txt");
    int count=StringLen(buffer);
    Print("",count);
    WriteFile("C:\\Test1.txt",buffer);   
//----
   return(0);
  }

string ReadFile (string path) 
  {
    Print("Path in reading",path);
    int handle=_lopen (path,OF_READ);     
     Print("Handle in read condition",handle);     
    if(handle<0) 
      {
        Print("",path); 
        return ("");
      }
    int result=_llseek (handle,0,SEEK_END); 
    Print("result",result);     
    if(result<0) 
      {
       // Print("Îøèáêà óñòàíîâêè óêàçàòåëÿ" ); 
        Print("Error placing the pointer" );
        return ("");
      }
    string buffer="";
    string char1="x";
    int count=0;
    result=_lread (handle,char1,1);
    while(result>=0) 
      {
        buffer=buffer+char1;
        char1="x";
        count++;
        result=_lread (handle,char1,1);
     }
    result=_lclose (handle);              
    if(result<0)  
      Print(" ",path);
    return (buffer);
  }
 
//+------------------------------------------------------------------+
//|  çàïèñàòü ñîäåðæèìîå áóôåðà ïî óêàçàííîìó ïóòè                   |
//+------------------------------------------------------------------+
void WriteFile (string path, string buffer) 
  {
    int count=StringLen (buffer); 
    int result;
    int handle=_lopen (path,OF_WRITE);
    Print("",handle);
    if(handle<0) 
      {
        handle=_lcreat (path,0);
        if(handle<0) 
          {
           Print ("if handle is less then zero",path);
            return;
          }
        result=_lclose (handle);
     }
    handle=_lopen (path,OF_WRITE);               
    if(handle<0) 
      {
        Print("if handle is less then zero in writing condition",path); 
        return;
      }
    result=_llseek (handle,0,SEEK_END);          
    if(result<0) 
      {
        return;
      }
    result=_lwrite (handle,buffer,count); 
    if(result<0)  
        Print(" ",path," ",count,"");
    result=_lclose (handle);              
    if(result<0)  
        Print(" ",path);
  }
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
but my code is not working can somebody help me ??
 
ankityadav:
Hi i m working on to save data in to any directory in csv format but my code is not working can somebody help me ??

Simply says the code is not working will not help us to help you. Give us a more detailed one, such as the outputs, results, etc ...
 
deysmacro:

Simply says the code is not working will not help us to help you. Give us a more detailed one, such as the outputs, results, etc ...

Ya sure what i m trying to do is reading from one text file i..e..test.text and writing the data in to test2.txt but it doesn't work from here

don't know if you this code and print as i already printed but not working from here can you help me ??from read function

 int result=_llseek (handle,0,SEEK_END); 
 
   int _lopen  (string path, int of);
   int _lcreat (string path, int attrib);
can't be used in b600+ as string are now Unicode not ASCII http://winapi.freetechsecrets.com/win32/WIN32lopen.htm
 
WHRoeder:
can't be used in b600+ as string are now Unicode not ASCII http://winapi.freetechsecrets.com/win32/WIN32lopen.htm

hi thanks for your reply can you tell me what function i used in place of as i m working this code as well but it also not working ??
//+------------------------------------------------------------------+
//|                                              File Read Write.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

// êîíñòàíòû äëÿ ôóíêöèè _lopen
#define OF_READ               0
#define OF_WRITE              1
#define OF_READWRITE          2
#define OF_SHARE_COMPAT       3
#define OF_SHARE_DENY_NONE    4
#define OF_SHARE_DENY_READ    5
#define OF_SHARE_DENY_WRITE   6
#define OF_SHARE_EXCLUSIVE    7

#import "kernel32.dll"
   int _lopen  (string path, int of);
   int _lcreat (string path, int attrib);
   int _llseek (int handle, int offset, int origin);
   int _lread  (int handle, string buffer, int bytes);
   int _lwrite (int handle, string buffer, int bytes);
   int _lclose (int handle);
   int CreateDirectoryA(string path, int atrr[]);
#import


string ReadFile (string path) 
  {
    int handle=_lopen (path,OF_READ);
    int read_size = 50;           
    string char50="a";
    if(handle<0) 
      {
        Print("path",path); 
        return ("");
      }
    int result=_llseek (handle,0,0);      
    if(result<0) 
      {
        Print("Error in pointing the file" ); 
        return ("");
      }
    string buffer="";
    int count=0;
    int last;
    
    result=_lread (handle,char50,read_size);
    while(result>0 && result == read_size) 
      {
        buffer=buffer + char50;
        count++;
        result=_lread (handle,char50,read_size);
        last = result;
     }
    Print(last);
    char50 = StringSubstr(char50,0,last);
    buffer = buffer + char50;    
    result=_lclose (handle);              
    if(result<0)  
      Print("Error in pointing the file ",path);
    return (buffer);
  }
 
//+------------------------------------------------------------------+
//|  çàïèñàòü ñîäåðæèìîå áóôåðà ïî óêàçàííîìó ïóòè                   |
//+------------------------------------------------------------------+
void WriteFile (string path, string buffer) 
  {
    int count=StringLen (buffer); 
    int result;
    int handle=_lopen (path,OF_WRITE);
    if(handle<0) 
      {
        handle=_lcreat (path,0);
        if(handle<0) 
          {
            Print ("",path);
            if (!CreateFullPath(path))
               {
               Print("",path);
               return;
               }
            else handle=_lcreat (path,0);   
          }
        result=_lclose (handle);
        handle = -1;
     }
    if (handle < 0) handle=_lopen (path,OF_WRITE);               
    if(handle<0) 
      {
        Print(" ",path); 
        return;
      }
    result=_llseek (handle,0,0);          
    if(result<0) 
      {
        Print(""); 
        return;
      }
    result=_lwrite (handle,buffer,count); 
    if(result<0)  
        Print(" ",path," ",count," áàéò");
    result=_lclose (handle);              
    if(result<0)  
        Print("Îøèáêà çàêðûòèÿ ôàéëà ",path);
    return;        
  }
//+------------------------------------------------------------------+
//|  ñîçäàåò âñå íåîáõîäèìûå ïàïêè è ïîäïàïêè                        |
//+------------------------------------------------------------------+
bool CreateFullPath(string path)
   {
   bool res = false;
   if (StringLen(path)==0) return(false);
   Print("",path);
//----
   string folders[];
   if (!ParsePath(folders, path)) return(false);
   Print("", ArraySize(folders));
   
   int empty[];
   int i = 0;
   while (CreateDirectoryA(folders[i],empty)==0) i++;
   Print("",folders[i]);
   i--;
   while (i>=0) 
      {
      CreateDirectoryA(folders[i],empty);
      Print("",folders[i]);
      i--;
      }
   if (i<0) res = true;   
//----
   return(res);
   }
   
//+------------------------------------------------------------------+
//| ðàçáèòü ïóòü íà ìàññèâ ïîäïàïîê                                  |
//+------------------------------------------------------------------+
bool ParsePath(string & folder[], string path)
   {
   bool res = false;
   int k = StringLen(path);
   if (k==0) return(res);
   k--;

   Print("", path);
   int folderNumber = 0;
//----
   int i = 0;
   while ( k >= 0 )
      {
       string st1 = StringGetChar(path, k);
      //Print("char = ",char, "=>",CharToStr(char));
      if ( st1 == 92) //  îáðàòíûé ñëåø "\"
         {
         if (StringGetChar(path, k-1)!= 92)
            {
            folderNumber++;
            ArrayResize(folder,folderNumber);
            folder[folderNumber-1] = StringSubstr(path,0,k);
            Print(folderNumber,":",folder[folderNumber-1]);
            }
         else break;         
         }
      k--;   
      }
   if (folderNumber>0) res = true;   
//----
   return(res);   
   }   
  
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
    int start = GetTickCount();
    string buffer=ReadFile("C:\\test.txt");

    int middle = GetTickCount();
    int count=StringLen(buffer);

    Print("",count);
    Print("buffer",buffer);
    WriteFile("C:\\folder_A\\folder_B\\folder_C\\folder_D\\test2.txt",buffer);   
    int finish = GetTickCount();
    Print("count ",count," bytes. ",(middle-start)," ",(finish-middle)," ms.");
//----
   return(0);
  }
//+------------------------------------------------------------------+
these to work out side the directory ??
Reason: