-
Hey peeps, I have a q...
I'm trying to convert a function I wrote in VB (yesss the one Vlatko has converted too, that was mine ;))
I was just beginning and was bouncing on an error already :(
Code:
void GetAllDirs(char cDirIn[256])
{
char d[256];
bool dr, dts;
long File;
int c;
WIN32_FIND_DATA FindData;
File = FindFirstFile(lstrcat(cDirIn, "*"), FindData);
if (File = -1) cout << "****!";
}
I'm getting this error
Code:
--------------------Configuration: ROKv2 - Win32 Debug--------------------
Compiling...
main.cpp
C:\Jop\Vc++\ROKv2\main.cpp(21) : error C2664: 'FindFirstFileA' : cannot convert parameter 2 from 'struct _WIN32_FIND_DATAA' to 'struct _WIN32_FIND_DATAA *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.
ROKv2.exe - 1 error(s), 0 warning(s)
I've included windows.h & iostream.h, so the functions can be called :(
As you might notice I'm really new in C++ so please help me ;)
thanx.
Oh vlatko, can you please give me the converted code (the Function I gave you (the GetAllDirs from my file module))
Thanks guys!
You translated it right?
(Editing)
By the way, here's the VB code for my function:
Code:
Public Sub GetAllFiles(startdir As String, Lst As ListBox)
Dim d$, dr As Boolean, dts As Boolean, dirs() As String
Dim FindData As WIN32_FIND_DATA, c%, File&
If Right(startdir, 1) <> "\" Then startdir = startdir & "\"
ReDim dirs(0)
File = FindFirstFile(startdir & "*", FindData)
c = 1
Do While c
c = FindNextFile(File, FindData)
d = StripNulls(FindData.cFileName)
dts = d <> "." And d <> ".." And Len(d) > 0
If dts Then dr = (GetFileAttributes(startdir & d) And FILE_ATTRIBUTE_DIRECTORY)
If dr = False And dts Then Lst.AddItem startdir & d 'add to list
If dr And dts Then
ReDim Preserve dirs(UBound(dirs) + 1)
dirs(UBound(dirs)) = d
End If
Loop
Dim x&
FindClose File
For x = 1 To UBound(dirs)
GetAllFiles startdir & dirs(x), Lst
Next x
End Sub
Thanx :)
[Edited by Jop on 01-05-2001 at 09:31 AM]
-
Never mind guys, I got it to work *thanx to chris!*
Here's the code that worked for me! ;)
Code:
#define _WIN32_WINNT 0x0400
#include <iostream.h>
#include <windows.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
void GetAllDirs(char cDirIn[256])
{
char d[256];
bool dr, dts;
HANDLE File;
long lAtt;
int c;
WIN32_FIND_DATA FindData;
File = FindFirstFile(lstrcat(cDirIn, "*"), &FindData);
if (File == INVALID_HANDLE_VALUE)
{
cout << "****!";
}
Vlatko, I still like to receive my code (translated to C++)
thanks.
-
You don't have to use the stripnulls function in C++. I didn't. Here is the code , it is a little changed (mixed up) and with some new lines of code. You may find it different because it uses MFC(CString). Should be no problem not to use char.
Code:
//in header CString dd = "" and CString tt="";
void CAllDlg::car1(CString dir)
{
vector<CString> vec;
WIN32_FIND_DATA finddata;
HANDLE file;
file = FindFirstFile(dir + "*",&finddata);
int c = 1;
int i = 0;
BOOL dts,dr;
do
{
c = FindNextFile(file,&finddata);
CString d = finddata.cFileName ;
dts = (d != "." && d != ".." && strlen(d) > 0);
dr = ((GetFileAttributes(dir + d) & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY);
if(dts == TRUE)
{
if(dr == FALSE)
{
if(dd != (dir+d))
{
l1.AddString (dir + d);
dd = (dir+d);
}
}
else if(dr == TRUE)
{
if(tt != d)
{
vec.push_back (d);
tt = d;
}
}
}
}while(c != 0);
FindClose(file);
long ff = vec.size ();
for(int x= 0;x<ff;++x)
car1(dir + vec.at (x) + "\\");
}
-
Nevermind ,i will send you the project.
-
Thanks vlatko, 'cause it was really driving me crazy :)
-
After your request on ICQ earlier, here's a non-MFC version:
Code:
#include <windows.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void DoFiles(string sRootPath, vector<string> &vsFileList) {
WIN32_FIND_DATA fndFiles;
HANDLE hSearch;
hSearch = FindFirstFile((sRootPath + "*").c_str(), &fndFiles);
// Ignores ".", so does not print first file found
while(FindNextFile(hSearch, &fndFiles)) {
// Do not accept ".." either
if(!strcmp(fndFiles.cFileName, "..")) continue;
// Add complete file & path to list
vsFileList.push_back(sRootPath + fndFiles.cFileName);
if(GetFileAttributes((sRootPath + fndFiles.cFileName).c_str()) & FILE_ATTRIBUTE_DIRECTORY) {
// It's a directory, so call this function again
DoFiles(sRootPath + fndFiles.cFileName + "\\", vsFileList);
}
}
FindClose(hSearch);
}
void main(int argc, char **argv) {
if(argc < 2) {
cout << "Usage: " << argv[0] << " <path>\n";
return;
}
vector<string> vsFiles;
DoFiles(argv[1], vsFiles);
for(int i = 0; i < vsFiles.size(); i++) {
cout << vsFiles[i] << endl;
}
}
-
Wooh thankssssss parksie!! it's working now :)