Rejoignez notre page de fans
- Vues:
- 3847
- Note:
- Publié:
- 2013.03.27 14:46
- Mise à jour:
- 2016.11.22 07:32
-
Besoin d'un robot ou d'un indicateur basé sur ce code ? Commandez-le sur Freelance Aller sur Freelance
The script searches all text files in the terminal local folder and deletes those of them whose creation data is less than the data value on the "InpFilesDate" input parameter. The terminal local folder location can be obtained calling the TerminalInfoString() function.
PrintFormat("The path to the terminal local folder: %s\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH));
Note: The script will delete all text files which were created earlier than January 1st, 2010 from the terminal local folder (the InpFilesDate parameter value is default). Thus, before launching it, make sure that you have no text files with an important information in the terminal local folder.
Code:
//--- show the window of input parameters when launching the script #property script_show_inputs //--- date for old files input datetime InpFilesDate=D'2010.01.01 00:00'; //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { string file_name; // variable for storing file names string filter="*.txt"; // filter for searching the files datetime create_date; // file creation date string files[]; // list of file names int def_size=25; // array size by default int size=0; // number of files //--- allocate memory for the array ArrayResize(files,def_size); //--- receive the search handle in the local folder's root long search_handle=FileFindFirst(filter,file_name); //--- check if FileFindFirst() executed successfully if(search_handle!=INVALID_HANDLE) { //--- searching files in the loop do { files[size]=file_name; //--- increase the array size size++; if(size==def_size) { def_size+=25; ArrayResize(files,def_size); } //--- reset the error value ResetLastError(); //--- receive the file creation date create_date=(datetime)FileGetInteger(file_name,FILE_CREATE_DATE,false); //--- check if the file is old if(create_date<InpFilesDate) { PrintFormat("%s file deleted!",file_name); //--- delete the old file FileDelete(file_name); } } while(FileFindNext(search_handle,file_name)); //--- close the search handle FileFindClose(search_handle); } else { Print("Files not found!"); return; } //--- check what files have remained PrintFormat("Results:"); for(int i=0;i<size;i++) { if(FileIsExist(files[i])) PrintFormat("%s file exists!",files[i]); else PrintFormat("%s file deleted!",files[i]); } }
Traduit du russe par MetaQuotes Ltd.
Code original : https://www.mql5.com/ru/code/1610
![Demo_FileCopy](https://c.mql5.com/i/code/script.png)
The script demonstrates the example of using the FileCopy() function
![Demo_FileFind](https://c.mql5.com/i/code/script.png)
The script is a simple example of using the FileFindFirst(), FileFindNext() and FileFindClose() functions
![The20sv0.20](https://c.mql5.com/i/code/indicator.png)
The semaphore trend signal indicator
![Demo_FileMove](https://c.mql5.com/i/code/script.png)
The script demonstrates the example of using the FileMove() function