Как получить все файлы в папке?
От: Ortistx  
Дата: 25.04.11 18:39
Оценка:
Здравствуйте.

Создаю консольное приложение в MS Visual Studio. На данном этапе разработки программы необходимо:
после ввода пути к папке в качестве параметра, определить какие файлы находятся в данной папке.

Собственно вопрос. Как можно получить список файлов, которые находятся в папке?

Заранее спасибо.
Re: Как получить все файлы в папке?
От: artem_korneev США https://www.linkedin.com/in/artemkorneev/
Дата: 25.04.11 19:06
Оценка: 1 (1)
Здравствуйте, Ortistx, Вы писали:

O>Собственно вопрос. Как можно получить список файлов, которые находятся в папке?


Boost сгодится?

Вот пример:

http://live.boost.org/doc/libs/1_46_1/libs/filesystem/v3/doc/tutorial.html#Directory-iteration
С уважением, Artem Korneev.
Re: Как получить все файлы в папке?
От: MasterZiv СССР  
Дата: 25.04.11 19:19
Оценка: 1 (1)
On 25.04.2011 22:39, Ortistx wrote:

> Собственно вопрос. Как можно получить список файлов, которые находятся в папке?


FindFirstFile, FindNextFile, and FindClose

или

These functions search for and close searches for specified file names:

_findclose

_findnext, _wfindnext

_findfirst, _wfindfirst

(всё Win32)

или

The Boost.Filesystem library provides portable facilities to query and
manipulate paths, files, and directories.

The following function, given a directory path and a file name, recursively
searches the directory and its sub-directories for the file name, returning a
bool, and if successful, the path to the file that was found. The code below is
extracted from a real program, slightly modified for clarity:

[code C++]
bool find_file( const path & dir_path, // in this directory,
const std::string & file_name, // search for this name,
path & path_found ) // placing path here if found
{
if ( !exists( dir_path ) ) return false;
directory_iterator end_itr; // default construction yields past-the-end
for ( directory_iterator itr( dir_path );
itr != end_itr;
++itr )
{
if ( is_directory(itr->status()) )
{
if ( find_file( itr->path(), file_name, path_found ) ) return true;
}
else if ( itr->leaf() == file_name ) // see below
{
path_found = itr->path();
return true;
}
}
return false;
}
[/code]
Posted via RSDN NNTP Server 2.1 beta
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.