Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 01:28
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (7th_zorro), 793 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
recursive directory/file listing #164466
10/30/07 17:42
10/30/07 17:42
Joined: May 2007
Posts: 175
Germany
dblade Offline OP
Member
dblade  Offline OP
Member

Joined: May 2007
Posts: 175
Germany
So, here is my problem:
I want to list all files of my main drive for example "C:\"
This could be realized with the FindFirstFile() and FindNextFile()
functions from the WinApi but also need a recursive function calling.
How to realize ?
Code:
scroll down !
-------------------------------------------------------------------------------
Also hier mein Problem:
Ich möchte alle Dateien von meiner Hauptfetplatte z.B "C:\"
auflisten. Dies kann mit den FindFirstFile() and FindNextFile() Funktionen
aus der WinApi realisiert werden benötigt aber die Verwendung rekursiver
Funktionsaufrufe.
Wie realisisere ich dass ?
Hier ist mein Code:

Code:

//Only a example so please don't blame me for syntax errors

#include <acknex.h>
#include <windows.h>
#include <stdio.h>

/*here I defined the WIN32_FIND_DATA and FILETIME structs furthermore the
TCHAR definitions*/

char main_str[10000]; //enough space ?

int list_files(char *dir) //for recursion
{
HANDLE main_handle;
WIN32_FIND_DATA main_data;
char path_str[500];

main_handle = FindFirstFile(dir,&main_data);

while(FindNextFile(main_handle,&main_data))
{
switch(main_data.dwFileAttributes)
{
case FILE_ATTRIBUTE_DIRECTORY:
sprintf(main_str,"[dir]");
sprintf(main_str,main_data.cFileName);
sprintf(main_str,"\n");
GetFullPathName(main_data.cFileName,path_str,4096,NULL);
list_files(path_str);
break;
default:
sprintf(main_str,"[file]");
sprintf(main_str,main_data.cFileName);
sprintf(main_str,"\n");
/*All other switches like FILE_ATTRIBUTE_ARCHIVE,etc.*/
}
}

int main()
{
wait(1);
list_files("C:\\*");
}



So far
But at the end the string only contains the files of the
folder given at the first function call ("C:\\*") and the
names of all subdirectories but not their files, so please help me.
-------------------------------------------------------------------------------
So weit
Aber der String enthält am Ende nur die Dateien des Verzeichnisses, dass beim
ersten Funktionsaufruf angegeben wurde ("C:\\*") und die Namen der Unter
verzeichnisse aber nicht deren Dateien.

Re: recursive directory/file listing [Re: dblade] #164467
10/30/07 18:35
10/30/07 18:35
Joined: Oct 2002
Posts: 4,753
Munich, Bavaria, South of Germ...
TripleX Offline
Expert
TripleX  Offline
Expert

Joined: Oct 2002
Posts: 4,753
Munich, Bavaria, South of Germ...
correct start:

Code:


if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
//////
}
else
{
//file
}



Re: recursive directory/file listing [Re: TripleX] #164468
10/30/07 18:45
10/30/07 18:45
Joined: May 2007
Posts: 175
Germany
dblade Offline OP
Member
dblade  Offline OP
Member

Joined: May 2007
Posts: 175
Germany
No, switch works, too (for me)(Don't know why but works fine).
Tested with normal Listing.

Re: recursive directory/file listing [Re: dblade] #164469
11/23/07 14:25
11/23/07 14:25
Joined: Oct 2002
Posts: 4,753
Munich, Bavaria, South of Germ...
TripleX Offline
Expert
TripleX  Offline
Expert

Joined: Oct 2002
Posts: 4,753
Munich, Bavaria, South of Germ...
A big warning: If you ever try to delete a complete folder this way, never, never yes really NEVER use an empty string for char* dir. It will delete your whole disk in less than 1 minute. You won't recognize this (the only thing you see is that the engine is hanging) and the files can't be restored with Recovery Tools (in my case ).

So be very very carful when using the code above for deleting whole folders.

Re: recursive directory/file listing [Re: TripleX] #164470
11/24/07 10:41
11/24/07 10:41
Joined: May 2007
Posts: 175
Germany
dblade Offline OP
Member
dblade  Offline OP
Member

Joined: May 2007
Posts: 175
Germany
Got it working but my next problem is the using of GetFullPathName.
Example:

I have found a folder on drive C:\ (maybe my_files) the full name should be
C:\my_files but when i use the GetFullPathName i got C:\Dev-Cpp\my_files\
because the test prog. is located in the Dev-Cpp dir.
The problem is it doesn't exist a C:\Dev-Cpp\my_files\ folder, so i can't work
with it.

I hope you can understand my problem

@TripleX maybe this is usefull to write a Virus ^^


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1