初学者的问题 MQL5 MT5 MetaTrader 5 - 页 950

 

谢谢你!那里不是那么容易,那么没有Win API就没有办法了吗?

 
Aleksey Vyazmikin:

谢谢你!那里不是那么容易,那么没有Win API就没有办法了吗?

在这种情况下,请阅读MQL5文档。

 
Aleksey Vyazmikin:

谢谢你!没那么简单,所以没有Win API就不能做?

这有什么好复杂的?我读了两段,就都明白了。

1.在指定的目录、公共或终端文件夹 中搜索所有的任何文件。你得到了通往他们的道路,一个接一个。

2.用这条线工作。在这一行中寻找指定的文件夹,并计算指定的文件夹名称出现了多少次。这将是该文件夹及其子文件夹中的文件数量。

 
Aleksey Vyazmikin:
你能告诉我如何获得指定目录MQL5\Files中的目录列表吗?
string GetDirectory( const string FileName )
{
  int Pos = ::StringFind(FileName, "\\");
  int LastPos = Pos;

  while (Pos >= 0)
  {
    LastPos = Pos;

    Pos = ::StringFind(FileName, "\\", Pos + 1);
  }

  return((LastPos >= 0) ? ::StringSubstr(FileName, 0, LastPos + 1) : "");
}

// Получает список всех директорий (c поддиректориями) песочницы
int GetDirectories( string &Directories[], int Pos = 0, string Filter = "*", const int Common_Flag = 0 )
{
  string FileName;
  const long handle = ::FileFindFirst(Filter, FileName, Common_Flag);

  if (handle != INVALID_HANDLE)
  {
    const string Directory = ::GetDirectory(Filter);
    Filter = ::StringSubstr(Filter, ::StringLen(Directory));

    do
    {
      const string TmpFileName = Directory + FileName;

      if (!::FileIsExist(TmpFileName, Common_Flag) && (::GetLastError() == ERR_FILE_IS_DIRECTORY)) // https://www.mql5.com/ru/forum/1111/page2337#comment_9723503
      {
        ::ResetLastError();
        
        ::ArrayResize(Directories, Pos + 1, 10000);
        Directories[Pos] = TmpFileName;
        Pos++;

        Pos = ::GetDirectories(Directories, Pos, TmpFileName + Filter, Common_Flag);
      }
    }
    while (::FileFindNext(handle, FileName));

    ::FileFindClose(handle);
  }

  return(Pos);
}

void OnStart()
{
  string Folders[];
  
  GetDirectories(Folders);
  
  ArrayPrint(Folders);
}

摘自这里。也许其他功能在那里会很有用。

MQL5 Site / file.mqh - Скачать бесплатно скрипт 'ThirdPartyTicks' от 'fxsaber' для MetaTrader 5 в MQL5 Code Base
  • www.mql5.com
class FILE { private:   static int GetFileNames( string &FileNames[], int Pos = 0, string Filter = "*", const int Common_Flag = 0 )   {       string FileName;       const long handle = ::FileFindFirst(Filter, FileName, Common_Flag);       if (handle != INVALID_HANDLE)       {         const string Directory = FILE::GetDirectory(Filter...
 
Vladimir Karputov:

然后从MQL5文件中。

谢谢,但现在还很难申请...

 
fxsaber:

摘自这里。也许那里的其他功能将是有用的。

谢谢,代码起作用了!还有,如何只获得指定目录中的目录名,而没有深度分支和文件名?

 
Aleksey Vyazmikin:

谢谢,代码起作用了!但是,如何只获得指定目录中的目录名,而没有深度分支和文件名?

//        Pos = ::GetDirectories(Directories, Pos, TmpFileName + Filter, Common_Flag);
 
fxsaber:

谢谢,但我想不出如何获得特定子目录中的目录,即我知道MQL5\Files有一个 "test "目录,我需要查看它的目录。

 
Aleksey Vyazmikin:

谢谢,但我想不出如何获得特定子目录中的目录,即我知道MQL5\Files有一个"test"目录,我需要查看它的目录。

  GetDirectories(Folders, 0, "test\\*");
 
fxsaber:

所以我做了,但文件也列在那里......如何区分文件 和文件夹还不清楚。