Объект FileSystemObject FileSystemObject object
Предоставляет доступ к файловой системе компьютера. Provides access to a computer’s file system.
Синтаксис Syntax
Scripting.FileSystemObject Scripting.FileSystemObject
Примечания Remarks
Приведенный ниже код иллюстрирует использование объекта FileSystemObject для возврата объекта TextStream, который можно читать, и в который можно записать данные. The following code illustrates how the FileSystemObject object is used to return a TextStream object that can be read from or written to:
В примере кода: In the example code:
- Функция CreateObject возвращает объект FileSystemObject ( fs ). The CreateObject function returns the FileSystemObject ( fs ).
- Метод CreateTextFile создает файл в качестве объекта TextStream ( a ). The CreateTextFile method creates the file as a TextStream object ( a ).
- Метод WriteLine записывает строку текста в созданный текстовый файл. The WriteLine method writes a line of text to the created text file.
- Метод Close опустошает буфер и закрывает файл. The Close method flushes the buffer and closes the file.
Методы Methods
Метод Method | Описание Description |
---|---|
BuildPath BuildPath | Добавляет имя в существующий путь. Appends a name to an existing path. |
CopyFile CopyFile | Копирует один или несколько файлов из одного расположения в другое. Copies one or more files from one location to another. |
CopyFolder CopyFolder | Копирует одну или несколько папок из одного расположения в другое. Copies one or more folders from one location to another. |
CreateFolder CreateFolder | Создает новую папку. Creates a new folder. |
CreateTextFile CreateTextFile | Создает текстовый файл и возвращает объект TextStream, который можно использовать для чтения или записи в файл. Creates a text file and returns a TextStream object that can be used to read from, or write to the file. |
DeleteFile DeleteFile | Удаляет один или несколько указанных файлов. Deletes one or more specified files. |
DeleteFolder DeleteFolder | Удаляет одну или несколько указанных папок. Deletes one or more specified folders. |
DriveExists DriveExists | Проверяет, существует ли указанный диск. Checks if a specified drive exists. |
FileExists FileExists | Проверяет, существует ли указанный файл. Checks if a specified file exists. |
FolderExists FolderExists | Проверяет, существует ли указанная папка. Checks if a specified folder exists. |
GetAbsolutePathName GetAbsolutePathName | Возвращает полный путь из корневого каталога диска для указанного пути. Returns the complete path from the root of the drive for the specified path. |
GetBaseName GetBaseName | Возвращает базовое имя указанного файла или папки. Returns the base name of a specified file or folder. |
GetDrive GetDrive | Возвращает объект Drive, соответствующий диску в указанном пути. Returns a Drive object corresponding to the drive in a specified path. |
GetDriveName GetDriveName | Возвращает имя диска указанного пути. Returns the drive name of a specified path. |
GetExtensionName GetExtensionName | Возвращает имя расширения файла для последнего компонента в указанном пути. Returns the file extension name for the last component in a specified path. |
GetFile GetFile | Возвращает объект файла для указанного пути. Returns a File object for a specified path. |
GetFileName GetFileName | Возвращает имя файла или папки для последнего компонента в указанном пути. Returns the file name or folder name for the last component in a specified path. |
GetFolder GetFolder | Возвращает объект Folder для указанного пути. Returns a Folder object for a specified path. |
GetParentFolderName GetParentFolderName | Возвращает имя родительской папки последнего компонента в указанном пути. Returns the name of the parent folder of the last component in a specified path. |
GetSpecialFolder GetSpecialFolder | Возвращает путь к некоторым специальным папкам Windows. Returns the path to some of Windows’ special folders. |
GetTempName GetTempName | Возвращает созданный случайным образом временный файл или папку. Returns a randomly generated temporary file or folder. |
Move Move | Перемещает заданный файл или указанную папку из одного места в другое. Moves a specified file or folder from one location to another. |
MoveFile MoveFile | Перемещает один или несколько файлов из одного места в другое. Moves one or more files from one location to another. |
MoveFolder MoveFolder | Перемещает одну или несколько папок из одного места в другое. Moves one or more folders from one location to another. |
OpenAsTextStream OpenAsTextStream | Открывает указанный файл и возвращает объект TextStream, который можно использовать для считывания, записи и дополнения данных в файле. Opens a specified file and returns a TextStream object that can be used to read from, write to, or append to the file. |
OpenTextFile OpenTextFile | Открывает файл и возвращает объект TextStream, который можно использовать для доступа к файлу. Opens a file and returns a TextStream object that can be used to access the file. |
WriteLine WriteLine | Записывает заданную строку и символ новой строки в файл TextStream. Writes a specified string and new-line character to a TextStream file. |
Свойства Properties
Свойство Property | Описание Description |
---|---|
Drives Drives | Возвращает коллекцию всех объектов Drive на компьютере. Returns a collection of all Drive objects on the computer. |
Name Name | Устанавливает или возвращает имя указанного файла или заданной папки. Sets or returns the name of a specified file or folder. |
Path Path | Возвращает путь для указанного файла, диска или указанной папки. Returns the path for a specified file, folder, or drive. |
Size Size | Для файлов возвращает размер указанного файла в байтах; для папок возвращает размер всех файлов и вложенных папок в байтах. For files, returns the size, in bytes, of the specified file; for folders, returns the size, in bytes, of all files and subfolders contained in the folder. |
Type Type | Возвращает сведения о типе файла или папки (например, для файлов с расширением .TXT возвращается «Text Document»). Returns information about the type of a file or folder (for example, for files ending in .TXT, «Text Document» is returned). |
См. также See also
Поддержка и обратная связь Support and feedback
Есть вопросы или отзывы, касающиеся Office VBA или этой статьи? Have questions or feedback about Office VBA or this documentation? Руководство по другим способам получения поддержки и отправки отзывов см. в статье Поддержка Office VBA и обратная связь. Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
FILE_OBJECT structure (wdm.h)
The FILE_OBJECT structure is used by the system to represent a file object. To user-mode protected subsystems, a file object represents an open instance of a file, device, directory, or volume. To device and intermediate drivers, a file object usually represents a device object. To drivers in the file system stack, a file object usually represents a directory or file.
A file object is partially opaque. Certain types of drivers, such as file system drivers and network transport drivers, use some of the fields of file objects.
Syntax
Members
A read-only member used by the system to indicate that the object is a file object. If the object is a file object, the value of this member is 5.
A read-only member that specifies the size, in bytes, of the file object. This size does not include the file object extension, if one is present.
A pointer to the device object on which the file is opened.
A pointer to the volume parameter block associated with the file object.
Note that if the Vpb member is non-NULL, the file resides on a mounted volume.
A pointer to whatever optional state a driver maintains about the file object; otherwise, NULL. For file system drivers, this member must point to a FSRTL_ADVANCED_FCB_HEADER header structure that is contained within a file-system-specific structure; otherwise system instability can result. Usually, this header structure is embedded in a file control block (FCB). However, on some file systems that support multiple data streams, such as NTFS, this header structure is a stream control block (SCB).
A pointer to whatever additional state a driver maintains about the file object; otherwise, NULL.
A pointer to the file object’s read-only section object. This member is set only by file systems and used for Cache Manager interaction.
An opaque member, set only by file systems, that points to handle-specific information and that is used for Cache Manager interaction.
A read-only member that is used, in certain synchronous cases, to indicate the final status of the file object’s I/O request.
A pointer to a FILE_OBJECT structure used to indicate that the current file object has been opened relative to an already open file object. The file object pointed to by this member is usually a directory (meaning the current file has been opened relative to this directory). However, a file can be reopened relative to itself, and alternate data streams for a file can be opened relative to an already open primary data stream for that same file. The RelatedFileObject member is only valid during the processing of the IRP_MJ_CREATE requests.
A read-only member. If FALSE, a lock operation (NtLockFile) has never been performed on the file object. If TRUE, at least one lock operation has been performed on the file object. Once set to TRUE, this member always remains TRUE (for example, releasing file locks on the file object does not reset this member to FALSE).
A read-only member. If TRUE, a delete operation for the file associated with the file object exists. If FALSE, there currently is no pending delete operation for the file object.
A read-only member. If TRUE, the file associated with the file object has been opened for read access. If FALSE, the file has been opened without read access. This information is used when checking and/or setting the share access of the file.
A read-only member. If TRUE, the file associated with the file object has been opened for write access. If FALSE, the file has been opened without write access. This information is used when checking and/or setting the share access of the file.
A read-only member. If TRUE, the file associated with the file object has been opened for delete access. If FALSE, the file has been opened without delete access. This information is used when checking and/or setting the share access of the file.
A read-only member. If TRUE, the file associated with the file object has been opened for read sharing access. If FALSE, the file has been opened without read sharing access. This information is used when checking and/or setting the share access of the file.
A read-only member. If TRUE, the file associated with the file object has been opened for write sharing access. If FALSE, the file has been opened without write sharing access. This information is used when checking and/or setting the share access of the file.
A read-only member. If TRUE, the file associated with the file object has been opened for delete sharing access. If FALSE, the file has been opened without delete sharing access. This information is used when checking and/or setting the share access of the file.
A read-only member used by the system to hold one or more (a bitwise inclusive OR combination) of the following private flag values.
Flag | Meaning |
---|---|
FO_FILE_OPEN | Deprecated. |
FO_SYNCHRONOUS_IO | The file object is opened for synchronous I/O. |
FO_ALERTABLE_IO | Any wait in the I/O manager, as a result of a request made to this file object, is alertable. |
FO_NO_INTERMEDIATE_BUFFERING | The file associated with the file object cannot be cached or buffered in a driver’s internal buffers. |
FO_WRITE_THROUGH | System services, file system drivers, and drivers that write data to the file must transfer the data into the file before any requested write operation is considered complete. |
FO_SEQUENTIAL_ONLY | The file associated with the file object was opened for sequential I/O operations only. |
FO_CACHE_SUPPORTED | The file associated with the file object is cacheable. This flag should be set only by a file system driver, and only if the FsContext member points to a valid FSRTL_ADVANCED_FCB_HEADER structure. |
FO_NAMED_PIPE | The file object represents a named pipe. |
FO_STREAM_FILE | The file object represents a file stream. |
FO_MAILSLOT | The file object represents a mailslot. |
FO_GENERATE_AUDIT_ON_CLOSE | Deprecated. |
FO_QUEUE_IRP_TO_THREAD | IRPs will not be queued to this file object. |
FO_DIRECT_DEVICE_OPEN | The device targeted by this file object was opened directly. |
FO_FILE_MODIFIED | The file associated with the file object has been modified. |
FO_FILE_SIZE_CHANGED | The file associated with the file object has changed in size. |
FO_CLEANUP_COMPLETE | The file system has completed its cleanup for this file object. |
FO_TEMPORARY_FILE | The file associated with the file object is a temporary file. |
FO_DELETE_ON_CLOSE | The file associated with the file object will be deleted by the file system upon close. |
FO_OPENED_CASE_SENSITIVE | The file name case of the file associated with the file object is respected. |
FO_HANDLE_CREATED | A file handle was created for file object. |
FO_FILE_FAST_IO_READ | A fast I/O read was performed on this file object. |
FO_RANDOM_ACCESS | The file associated with the file object was opened for random access. |
FO_FILE_OPEN_CANCELLED | The create request for this file object was canceled before completing. |
FO_VOLUME_OPEN | The file object represents a volume open request. |
FO_REMOTE_ORIGIN | The create request for the file associated with the file object originated on a remote machine. |
FO_SKIP_COMPLETION_PORT | For a file object associated with a port, determines if the system should skip queuing to the completion port when the IRP is completed synchronously with a non-error status return value. |
FO_SKIP_SET_EVENT | Skip setting the event for the file object upon IRP completion. |
FO_SKIP_SET_FAST_IO | Skip setting an event supplied to a system service when the fast I/O path is successful. |
A UNICODE_STRING structure whose Buffer member points to a read-only Unicode string that holds the name of the file opened on the volume. If the volume is being opened, the Length member of the UNICODE_STRING structure will be zero. Note that the file name in this string is valid only during the initial processing of an IRP_MJ_CREATE request. This file name should not be considered valid after the file system starts to process the IRP_MJ_CREATE request. The storage for the string pointed to by the Buffer member of the UNICODE_STRING structure is allocated in paged system memory. For more information about obtaining a file name, see FltGetFileNameInformation.
A read-only member that specifies the file offset, in bytes, associated with the file object.
A read-only member used by the system to count the number of outstanding waiters on a file object opened for synchronous access.
A read-only member used by the system to indicate whether a file object opened for synchronous access is currently busy.
An opaque pointer to the last lock applied to the file object.
An opaque member used by the system to hold a file object event lock. The event lock is used to control synchronous access to the file object. Applicable only to file objects that are opened for synchronous access.
An opaque member used by the system to hold an event object for the file object. The event object is used to signal the completion of an I/O request on the file object if no user event was supplied or a synchronous API was called.
An opaque pointer to completion port information (port pointer and key) associated with the file object, if any.
An opaque pointer to a KSPIN_LOCK structure that serves as the spin lock used to synchronize access to the file object’s IRP list.
An opaque pointer to the head of the IRP list associated with the file object.
An opaque pointer to the file object’s file object extension (FOBX) structure. The FOBX structure contains various opaque contexts used internally as well as the per-file object contexts available through FsRtlXxx routines.
Remarks
Drivers can use the FsContext and FsContext2 members to maintain driver-determined state about an open file object. A driver cannot use these members unless the file object is accessible in the driver’s I/O stack location of an IRP.
All remaining members in a file object are either opaque or read-only:
- Opaque members within a file object should be considered inaccessible. Drivers with dependencies on object field locations or access to opaque members might not remain portable and interoperable with other drivers over time.
- Drivers can use read-only members to acquire relevant information but must not modify read-only members and, if a pointer, the object that the member points to.
During the processing of an IRP_MJ_CREATE request, a file system driver calls the IoSetShareAccess routine (if the client is the first to open the file) or the IoCheckShareAccess routine (for subsequent clients that want to share the file). IoSetShareAccess and IoCheckShareAccess update the ReadAccess, WriteAccess, and DeleteAccess members to indicate the access rights that are granted to the client if the client has exclusive access to the file. Additionally, IoCheckShareAccess updates the SharedRead, SharedWrite, and SharedDelete members to indicate the access rights that are simultaneously granted to two or more clients that share the file. If the driver for a device other than a file system has to monitor the access rights of clients, this driver typically stores access rights information in context buffers that are pointed to by the FsContext and FsContext2 members.
CLFS clients do not directly access the members of a LOG_FILE_OBJECT structure.