Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (Ayumi), 1,088 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
How get list of subdir #216923
07/19/08 23:24
07/19/08 23:24
Joined: Jun 2008
Posts: 151
Ukraine
XD1v0 Offline OP
Member
XD1v0  Offline OP
Member

Joined: Jun 2008
Posts: 151
Ukraine
In my project i want use some file manipulations, so i need list of subfolders, how i get it in Lite-c?
I have plugin for A6 Files.dll but this plugin dont work in Lite-c.
Please help.


Last edited by XD1v0; 07/19/08 23:26.

A7 Commercial cool
Celeron 1700, GeForce 5500 FX 256mb, 1 Gb Ram
Re: How get list of subdir [Re: XD1v0] #216924
07/19/08 23:35
07/19/08 23:35
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
the source of files.dll

Code:
#include "stdafx.h"
#define DLL_USE
#include "adll.h"
#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <io.h>
#include <time.h>


BOOL APIENTRY DllMain( 
  HANDLE hModule,
  DWORD ul_reason_for_call,
  LPVOID lpReserved)
{
  engine_bind();
  return TRUE;
}


// get the file attributes
DLLFUNC file_attrib(STRING* filepath,var funcmode)
{
	struct _finddata_t c_file;
	long lFile=0;
	lFile=_findfirst( _CHR(filepath), &c_file );
	if(lFile<0){return _VAR(-1);}
	if(funcmode==0){return ((c_file.attrib & _A_RDONLY) ? _VAR(1) : _VAR(0));}
	if(funcmode==1){return ((c_file.attrib & _A_HIDDEN) ? _VAR(1) : _VAR(0));}
	if(funcmode==2){return ((c_file.attrib & _A_SYSTEM) ? _VAR(1) : _VAR(0));}
	if(funcmode==3){return ((c_file.attrib & _A_ARCH) ? _VAR(1) : _VAR(0));}
}

//listing all files in the folder, \n as seperator
DLLFUNC file_list(STRING* wildcard,STRING* buf)
{
	struct _finddata_t c_file;
	long lFile=0;
	lFile=_findfirst( _CHR(wildcard), &c_file );
	if(lFile<0){return 0;}
	str_cpy(buf,c_file.name);
	str_cat(buf,"\n");
	while(_findnext(lFile,&c_file)==0)
	{
		str_cat(buf,c_file.name);
		str_cat(buf,"\n");
	}
}

//get the filenames from a directory
DLLFUNC file_get(STRING* wildcard, var number)
{
	static STRING *buf = (STRING*)engine_getobj("foundfile");
	struct _finddata_t c_file;
	long lFile=0;
	int stop = _INT(number);
	int i=2;
	lFile=_findfirst( _CHR(wildcard), &c_file );
	if(lFile<0){return _VAR(0);}
	if(stop==1){str_cpy(buf,c_file.name); return _VAR(1);}

	while((_findnext(lFile,&c_file)==0)&&(stop!=i))
	{
		i++;
	}
	str_cpy(buf,c_file.name);
	return _VAR(1);
}

//count all files
DLLFUNC file_count(STRING* dir)
{
	struct _finddata_t c_file;
	long lFile=0;
	int i=1;
	int j=0;
	lFile=_findfirst( _CHR(dir), &c_file );
	if(lFile<0){return _VAR(0);}
	j+=(c_file.attrib & _A_SUBDIR) ? 0 : 1;
	while(_findnext(lFile,&c_file)==0)
	{
		j+=(c_file.attrib & _A_SUBDIR) ? 0 : 1;
		i++;
	}
	return _VAR(j);
}

//count subfolders
DLLFUNC folder_count(STRING* dir)
{
	struct _finddata_t c_file;
	long lFile=0;
	int i=1;
	int j=0;
	lFile=_findfirst( _CHR(dir), &c_file );
	if(lFile<0){return _VAR(0);}
	j+=(c_file.attrib & _A_SUBDIR) ? 1 : 0;
	while(_findnext(lFile,&c_file)==0)
	{
		j+=(c_file.attrib & _A_SUBDIR) ? 1 : 0;
		i++;
	}
	return _VAR(j);
}

//list subfolders
DLLFUNC folder_list(STRING* wildcard,STRING* buf)
{
	struct _finddata_t c_file;
	long lFile=0;
	bool isdir=false;
	lFile=_findfirst( _CHR(wildcard), &c_file );
	if(lFile<0){return 0;}
	isdir=(c_file.attrib & _A_SUBDIR) ? true : false;
	if(isdir)
	{
		str_cat(buf,c_file.name);
		str_cat(buf,"\n");
	}
	while(_findnext(lFile,&c_file)==0)
	{
		isdir=(c_file.attrib & _A_SUBDIR) ? true : false;
		if(isdir)
		{
			str_cat(buf,c_file.name);
			str_cat(buf,"\n");
		}
	}
}

//rename a folder
DLLFUNC folder_rename(STRING* oldname,STRING* newname)
{
	int a = rename(_CHR(oldname),_CHR(newname));
	if(a==0){return _VAR(1);}
	return _VAR(0);
}

//read out creation/last-access/last-edit date of the file/folder
DLLFUNC file_date(STRING* filename,var funcmode)
{
	static STRING *buf = (STRING*)engine_getobj("foundfile");
	struct _finddata_t c_file;
	long lFile=0;
	lFile=_findfirst( _CHR(filename), &c_file );
	if(lFile<0){return _VAR(0);}
	
	if(_INT(funcmode)==0){str_cpy(buf,ctime( &( c_file.time_create )));}
	if(_INT(funcmode)==1){str_cpy(buf,ctime( &( c_file.time_access )));}
	if(_INT(funcmode)==2){str_cpy(buf,ctime( &( c_file.time_write )));}
}

//get the foldernames from a directory
DLLFUNC folder_get(STRING* wildcard, var number)
{
	static STRING *buf = (STRING*)engine_getobj("foundfile");
	struct _finddata_t c_file;
	long lFile=0;
	int stop = _INT(number);
	int i=1;
	bool isdir=false;
	lFile=_findfirst( _CHR(wildcard), &c_file );
	if(lFile<0){return _VAR(0);}
	isdir=(c_file.attrib & _A_SUBDIR) ? true : false;
	if((isdir)&&(stop==1))
	{
		str_cpy(buf,c_file.name);
	}
	while((_findnext(lFile,&c_file)==0)&&(stop!=i))
	{
		isdir=(c_file.attrib & _A_SUBDIR) ? true : false;
		if(isdir)
		{
			str_cpy(buf,c_file.name);
			i++;
		}
		
	}
	return _VAR(1);
}


compile it with latest engine sdk and it should work with lite-c. of courese you will need a new header.


3333333333
Re: How get list of subdir [Re: Quad] #216925
07/20/08 00:06
07/20/08 00:06
Joined: Jun 2008
Posts: 151
Ukraine
XD1v0 Offline OP
Member
XD1v0  Offline OP
Member

Joined: Jun 2008
Posts: 151
Ukraine
Originally Posted By: Quadraxas
compile it with latest engine sdk and it should work with lite-c. of courese you will need a new header.

Sory but I dont have C++ compiler. It must be another way, maybe i can use windows.h, here 2 function but I dont know how to use it.

long WINAPI FindFirstFile(long lpFileName,long lpFindFileData);
long WINAPI FindNextFile(long hFindFile,long lpFindFileData);


A7 Commercial cool
Celeron 1700, GeForce 5500 FX 256mb, 1 Gb Ram
Re: How get list of subdir [Re: XD1v0] #216927
07/20/08 01:25
07/20/08 01:25
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
yea. This should do the job:

lite-c code:
Code:
#include <acknex.h>
#include <windows.h>
long WINAPI FindFirstFile(long lpFileName,long lpFindFileData);
long WINAPI FindNextFile(long hFindFile,long lpFindFileData);

int main(){
	WIN32_FIND_DATA ffd;
   HANDLE hFind = INVALID_HANDLE_VALUE;
	

   hFind = FindFirstFile("*", &ffd);

   while (FindNextFile(hFind, &ffd) != 0)
   {
      if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
      {
         printf("  %s   <DIR>\n", ffd.cFileName);
      }
   }
   FindClose(hFind);
}


run it and you will get the idea.

edit: Beware, no error handling in this code. i made it as simple as possbile.

Last edited by Quadraxas; 07/20/08 01:27.

3333333333
Re: How get list of subdir [Re: Quad] #216942
07/20/08 07:35
07/20/08 07:35
Joined: Jun 2008
Posts: 151
Ukraine
XD1v0 Offline OP
Member
XD1v0  Offline OP
Member

Joined: Jun 2008
Posts: 151
Ukraine
It does not work cry
I get error



A7 Commercial cool
Celeron 1700, GeForce 5500 FX 256mb, 1 Gb Ram
Re: How get list of subdir [Re: XD1v0] #216953
07/20/08 10:32
07/20/08 10:32
Joined: Jun 2008
Posts: 151
Ukraine
XD1v0 Offline OP
Member
XD1v0  Offline OP
Member

Joined: Jun 2008
Posts: 151
Ukraine
Hurra, I found a method cool
Code:
#include <acknex.h>
#include <windows.h>

typedef struct _FILETIME {
  DWORD dwLowDateTime;
  DWORD dwHighDateTime;
} FILETIME; 

typedef struct _WIN32_FIND_DATA {
  DWORD dwFileAttributes;
  FILETIME ftCreationTime;
  FILETIME ftLastAccessTime;
  FILETIME ftLastWriteTime;
  DWORD nFileSizeHigh;
  DWORD nFileSizeLow;
  DWORD dwReserved0;
  DWORD dwReserved1;
  char cFileName[ MAX_PATH ];
  char cAlternateFileName[ 14 ];
} WIN32_FIND_DATA;

int main(){
	
WIN32_FIND_DATA ffd;
   HANDLE hFind = INVALID_HANDLE_VALUE;


   hFind = FindFirstFile("*", &ffd);

   while (FindNextFile(hFind, &ffd) != 0)
   {
      if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
      {
         printf("  %s   <DIR>\n", ffd.cFileName);
      }
   }
   FindClose(hFind);
}


Thank you Quadraxas, without your help I would not manage smile

Last edited by XD1v0; 07/20/08 10:39.

A7 Commercial cool
Celeron 1700, GeForce 5500 FX 256mb, 1 Gb Ram
Re: How get list of subdir [Re: XD1v0] #216964
07/20/08 11:59
07/20/08 11:59
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
try upgrading to 1.10 and i guess you wont need this defines??

the code i posted worked with a7.10 commerical without defines.

anyway good to hear you solved it, good luck with your project.


3333333333
Re: How get list of subdir [Re: Quad] #216991
07/20/08 16:26
07/20/08 16:26
Joined: Jul 2007
Posts: 959
nl
F
flits Offline
User
flits  Offline
User
F

Joined: Jul 2007
Posts: 959
nl
i dont know if its what your are seaching for but you can try it anyway

txt_for_dir


"empty"

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