Получить несколько файлов по маске - VB

Узнай цену своей работы

Формулировка задачи:

Подскажите, пожалуйста, как можно узнать о наличии более чем одного файла в каталоге по маске и получить их имена. DIR() - всегда возвращает только один файл. Заранее благодарен. Юрий.

Решение задачи: «Получить несколько файлов по маске»

textual
Листинг программы
  1. Dir Function Example
  2.  
  3. This example uses the Dir function to check if certain files and directories exist.
  4.  
  5. Dim MyFile, MyPath, MyName
  6. ' Returns 'WIN.INI'  if it exists.
  7. MyFile = Dir('C:WINDOWSWIN.INI')  
  8.  
  9. ' Returns filename with specified extension. If more than one *.ini
  10. ' file exists, the first file found is returned.
  11. MyFile = Dir('C:WINDOWS*.INI')
  12.  
  13. ' Call Dir again without arguments to return the next *.INI file in the
  14. ' same directory.
  15. MyFile = Dir
  16.  
  17. ' Return first *.TXT file with a set hidden attribute.
  18. MyFile = Dir('*.TXT', vbHidden)
  19.  
  20. ' Display the names in C: that represent directories.
  21. MyPath = 'c: '   ' Set the path.
  22. MyName = Dir(MyPath, vbDirectory)   ' Retrieve the first entry.
  23. Do While MyName <> ''   ' Start the loop.
  24.   ' Ignore the current directory and the encompassing directory.
  25.   If MyName <> '.' And MyName <> '..' Then
  26.      ' Use bitwise comparison to make sure MyName is a directory.
  27.      If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
  28.          Debug.Print MyName   ' Display entry only if it
  29.      End If   ' it represents a directory.
  30.   End If
  31.    MyName = Dir   ' Get next entry.
  32. Loop

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

9   голосов , оценка 4.111 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут