libérer un dossier après utilisation des APIs de recherche de fichiers, FindFirstFile et FindClose
bonjour à tous,
J'ai développer le programme suivant pour extraire le nom d'un dossier et ça fonctionne convenablement:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
//Path of the working directory
const char * l_strPath;
HANDLE hFind;
WIN32_FIND_DATA FindFileData;
l_strPath = i_strWorkingDirectory.c_str();
try
{
SetCurrentDirectory (l_strPath);
hFind = FindFirstFile("*.*", &FindFileData);
while (FindNextFile (hFind, &FindFileData))
{
if (strcmp(FindFileData.cFileName,".")!=0 &&
strcmp(FindFileData.cFileName,"..")!=0 &&
FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
{
o_strFSDFEDirectory = FindFileData.cFileName;
}
}
}
catch(ETMException& )
{
cout << "FSDFE directory doesn't exist << endl;
} |
Le problème c'est que je peux plus faire aucune modification (renommage ou suppression) sur le dossier dans la suite du programme.
Est ce qu'il y a un moyen pour libérer le dossier après utilisation des APIs de recherche de fichiers, FindFirstFile et FindClose????
Merci d'avance 8-)
libérer un dossier après utilisation de la fonction SetCurrentDirectory
Oui j'ai oublier de mettre FindClose (hFind) après la boucle while.
Mais ça ne résout pas le problème. Le code est devenu comme suit:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
//Path of the working directory
const char * l_strPath;
HANDLE hFind;
WIN32_FIND_DATA FindFileData;
l_strPath = i_strWorkingFSDFEDirectory.c_str();
try
{
SetCurrentDirectory (l_strPath);
hFind = FindFirstFile("*.*", &FindFileData);
while (FindNextFile (hFind, &FindFileData))
{
if (!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
o_strFSDFEFileName = FindFileData.cFileName;
}
}
FindClose (hFind);
}
catch(...)
{
cout << "the file doesn't exist << endl;
} |
Je croix que le problème en fait est du à l'utilisation de la fonction SetCurrentDirectory (l_strPath);
Est ce qu'il y a une méthode qui permet de libérer le dossier après l'avoir choisit comme dossier courant??
Merci!