Visual Basic, .NET, ASP, VBScript
 

   
   
     

Форум - VBA

Страница: 1 |

 

  Вопрос: работа с dir,помогите... Добавлено: 11.06.09 02:02  

Автор вопроса:  LEX1ERS | ICQ: 4204936 
Не могли бы,описать мне все функции и работу с dir?в том числе как произвести поиск...Спасибо

Ответить

  Ответы Всего ответов: 4  

Номер ответа: 1
Автор ответа:
 Arvitaly



ICQ: 301746136 

Вопросов: 28
Ответов: 549
 Web-сайт: okazani.ru
 Профиль | | #1
Добавлено: 11.06.09 11:35
описать мне все функции


Даже не знаю с какой начать...

Ответить

Номер ответа: 2
Автор ответа:
 AngryBadger



Вопросов: 33
Ответов: 245
 Профиль | | #2 Добавлено: 11.06.09 12:33
Советую посмотреть тут.

http://www.vbnet.ru/vbguide/

Ответить

Номер ответа: 3
Автор ответа:
 AndreyMp



ICQ: 237822510 

Вопросов: 28
Ответов: 1182
 Профиль | | #3 Добавлено: 11.06.09 13:26
Пример из учебника (кажется Климова)
Dir [(pathname[, attributes])] - Возвращает строку, содержащую имя файла или директории, которое совпадает с определённой маской, атрибутом или меткой диска.
Пример:
Dim MyFile, MyPath, MyName
MyFile = Dir("C:\WINDOWS\WIN.INI";)
' Возвратит "WIN.INI" если файл существует.
MyFile = Dir("C:\WINDOWS\*.INI";)
' Возвратит имя файла с расширением INI.
' Если файлов несколько, то возвратится имя первого файла.
' Снова вызываем ф-цию Dir, только без параметров,
' чтобы получить имя следующего файла
' с расширением INI в директории WINDOWS
MyFile = Dir
' Возвратит имя первого файла
' с расширением TXT и атрибутом "скрытый"
MyFile = Dir("*.TXT", vbHidden)
' Нижеприведённый кусок кода
' отобразит в окне Immediate список папок
' в корневой директории на диске С

MyPath = "C:\"
MyName = Dir(MyPath, vbDirectory)
' Возвратит первую директорию.
Do While MyName <> "" ' Начало цикла
' Игнорируем текущую директорию или заключительную
If MyName <> "." And MyName <> ".." Then
' Используем битовое сравнение, чтобы определить
' что MyName есть директория (а не файл).
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
Debug.Print MyName ' Отобразим в окне Immediate MyName
End If
End If
MyName = Dir.
Loop

Ответить

Номер ответа: 4
Автор ответа:
 mc-black



ICQ: 308-534-060 

Вопросов: 20
Ответов: 1860
 Web-сайт: mc-black.narod.ru/dzp.htm
 Профиль | | #4
Добавлено: 12.06.09 11:27
Справка VBA в Microsoft Office:

  1. Dir Function


Returns a String representing the name of a file, directory, or folder that matches a specified pattern or file attribute, or the volume label of a drive.

Syntax
  1. Dir[(pathname[, attributes])]


The Dir function syntax has these parts:

Part Description
pathname Optional. String expression that specifies a file name — may include directory or folder, and drive. A zero-length string ("";) is returned if pathname is not found.
attributes Optional. Constant or numeric expression, whose sum specifies file attributes. If omitted, returns files that match pathname but have no attributes.



Settings

The attributes argument settings are:

Constant Value Description
vbNormal 0 (Default) Specifies files with no attributes.
vbReadOnly 1 Specifies read-only files in addition to files with no attributes.
vbHidden 2 Specifies hidden files in addition to files with no attributes.
VbSystem 4 Specifies system files in addition to files with no attributes. Not available on the Macintosh.
vbVolume 8 Specifies volume label; if any other attributed is specified, vbVolume is ignored. Not available on the Macintosh.
vbDirectory 16 Specifies directories or folders in addition to files with no attributes.
vbAlias 64 Specified file name is an alias. Available only on the Macintosh.



Note These constants are specified by Visual Basic for Applications and can be used anywhere in your code in place of the actual values.

Remarks

In Microsoft Windows, Dir supports the use of multiple character (*) and single character (?) wildcards to specify multiple files. On the Macintosh, these characters are treated as valid file name characters and can't be used as wildcards to specify multiple files.

Since the Macintosh doesn't support the wildcards, use the file type to identify groups of files. You can use the MacID function to specify file type instead of using the file names. For example, the following statement returns the name of the first TEXT file in the current folder:

  1. Dir("SomePath", MacID("TEXT"))


To iterate over all files in a folder, specify an empty string:

  1. Dir("")


If you use the MacID function with Dir in Microsoft Windows, an error occurs.

Any attribute value greater than 256 is considered a MacID value.

You must specify pathname the first time you call the Dir function, or an error occurs. If you also specify file attributes, pathname must be included.

Dir returns the first file name that matches pathname. To get any additional file names that match pathname, call Dir again with no arguments. When no more file names match, Dir returns a zero-length string "". Once a zero-length string is returned, you must specify pathname in subsequent calls or an error occurs. You can change to a new pathname without retrieving all of the file names that match the current pathname. However, you can't call the Dir function recursively. Calling Dir with the vbDirectory attribute does not continually return subdirectories.

Tip Because file names are retrieved in no particular order, you may want to store returned file names in an array, and then sort the array.

Ответить

Страница: 1 |

Поиск по форуму



© Copyright 2002-2011 VBNet.RU | Пишите нам