|
#include <iostream>
#include <iterator>
#include <sstream>
#include <string>
#include <cstring>
#include <list>
#include <algorithm>
#include "windows.h"
#include "stdlib.h"
#include "Chdir.h"
#include "file.h"
//
std :: list <std :: string> dirs, files;
//
void path_list (const char * fname) {
using namespace std;
Chdir set_path;
set_path.cd (fname);
WIN32_FIND_DATA FindFileData;
HANDLE hFind = INVALID_HANDLE_VALUE;
DWORD dwError;
// cout << "Target directory is" << path << ".\n";
char aim [MAX_PATH];
strncpy (aim, fname, strlen (fname) +1);
strncat (aim, "\\*", 3);
hFind = FindFirstFile (aim,&FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
cerr << "FindFirstFile (" << aim << ",&FindFileData) run error!\n";
exit (GetLastError ());
}
else
{
// cout << "First file name is" << FindFileData.cFileName << "\n";
char s [MAX_PATH];
if (0! = strcmp (".", FindFileData.cFileName)) {
_fullpath (s, FindFileData.cFileName, MAX_PATH);
files.push_back (s);
}
while (FindNextFile (hFind,&FindFileData)! = 0)
{
if (0 == strcmp ("..", FindFileData.cFileName)) continue;
if (FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) {
_fullpath (s, FindFileData.cFileName, MAX_PATH);
dirs.push_back (s);
}
else {
_fullpath (s, FindFileData.cFileName, MAX_PATH);
files.push_back (s);
}
}
dwError = GetLastError ();
FindClose (hFind);
if (dwError! = ERROR_NO_MORE_FILES)
{
cerr << "FindNextFile error!\n";
exit (dwError);
}
}
}
//
void full_path_list (const char * fname) {
using namespace std;
Chdir set_path;
set_path.cd (fname);
WIN32_FIND_DATA FindFileData;
HANDLE hFind = INVALID_HANDLE_VALUE;
DWORD dwError;
// cout << "Target directory is" << path << ".\n";
char aim [MAX_PATH];
strncpy (aim, fname, strlen (fname) +1);
strncat (aim, "\\*", 3);
hFind = FindFirstFile (aim,&FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
cerr << "FindFirstFile (" << aim << ",&FindFileData) run error!\n";
exit (GetLastError ());
}
else
{
// cout << "First file name is" << FindFileData.cFileName << "\n";
char s [MAX_PATH];
if (0! = strcmp (".", FindFileData.cFileName)) {
_fullpath (s, FindFileData.cFileName, MAX_PATH);
files.push_back (s);
}
while (FindNextFile (hFind,&FindFileData)! = 0)
{
if (0 == strcmp ("..", FindFileData.cFileName)) continue;
if (FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) {
_fullpath (s, FindFileData.cFileName, MAX_PATH);
dirs.push_back (s);
full_path_list (s);
}
else {
_fullpath (s, FindFileData.cFileName, MAX_PATH);
files.push_back (s);
}
}
dwError = GetLastError ();
FindClose (hFind);
if (dwError! = ERROR_NO_MORE_FILES)
{
cerr << "FindNextFile error!\n";
exit (dwError);
}
}
} |
|