hFind return INVALID_HANDLE_VALUE
Jun 25, 2013 at 9:56am UTC
Hi!
For my first post in the forum, and because i'm a real beginner, i don't see from where does my error come from. After a selection of multiple files in a folder by the user, i try to rename them, as "image_1.jpg", "image_2.jpg" etc...
I thought my code was good, but i probably did a mistake because it didn't rename, because hFind is always INVALID_HANDLE_VALUE. Can you help me and show me where does that come from? Thank you very much!!
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39
string cam;
if (radioButton1->Checked == true ){
cam="CDB" ;
}else if (radioButton2->Checked == true ){
cam="CDH" ;
}else if (radioButton3->Checked == true ){
cam="CGB" ;
}else if (radioButton3->Checked == true ){
cam="CGH" ;
}
string sfol;
ifstream fich_chemin("chemin.txt" );
getline(fich_chemin,sfol);
fich_chemin.close();
WIN32_FIND_DATA ffd;
string Dossier = sfol+"\\calib_interne\\TOOLBOX_calib\\" + cam + "\\*.jpg" ;
cout << Dossier << endl;
TCHAR* dirname = (TCHAR*)Dossier.c_str();
HANDLE hFind;
hFind = FindFirstFile((LPCWSTR)Dossier.c_str(), &ffd);
if (hFind == INVALID_HANDLE_VALUE){
cout << "erreur" << endl;
}
LPTSTR oldfilename;
TCHAR newfile[260];
LPTSTR newfilename = &newfile[0];
int i=1;
while (FindNextFile(hFind, &ffd)!=0)
{
cout << "le premier fichier est " << ffd.cFileName << endl;
oldfilename=ffd.cFileName;
StringCchPrintf(newfilename,8,TEXT("%s\\image_%d.jpg" ),dirname, i);
BOOL rs = MoveFile(oldfilename,newfilename);
i++;
}
FindClose(hFind);
Jun 25, 2013 at 10:04am UTC
Did you forget to include libraries?
Jun 25, 2013 at 10:16am UTC
No, here there are :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include "stdafx.h"
#include "Accueil.h"
#include <iostream>
#include <string>
#include <math.h>
#include "calib_cam_relative.h"
#include "calib_las_veh.h"
#include "calib_cam_las.h"
#include "calib_interne.h"
#include <stdio.h>
#include <strsafe.h>
#include <stdlib.h>
#include <fstream>
#include <sstream>
#include <windows.h>
#include<shellapi.h>
#include<conio.h>
Jun 25, 2013 at 10:24am UTC
I think #include <string> should be #include <cstring>
Jun 25, 2013 at 12:10pm UTC
GetLastError send me : "File not found" but when I print the "Dossier", it's the good path.
The error seems to come from my (LPCWSTR)Dossier...
Topic archived. No new replies allowed.