Who's Online
198 user(s) are online (
105 user(s) are browsing
Forums )
Members: 2
Guests: 196
Lio ,
trixie ,
more...
Headlines
mce.lha - game/utility
Apr 23, 2024
theme_list.lha - utility/misc
Apr 23, 2024
faac.lha - audio/convert
Apr 22, 2024
faad2.lha - audio/convert
Apr 22, 2024
seq.lha - audio/misc
Apr 22, 2024
libfaac.lha - development/library/audio
Apr 22, 2024
libfaad.lha - development/library/audio
Apr 22, 2024
image2pdf.lha - utility/text/convert
Apr 22, 2024
libharfbuzz.lha - development/library/graphics
Apr 20, 2024
libpng.lha - development/library/graphics
Apr 20, 2024
Topic options
View mode
Newest First
What the best and fast way to get list of files/dirs in the directory
Posted on:
2018/11/18 13:07
#1
Home away from home
Joined: 2007/9/11 12:31Last Login
: Today 18:54
From Russia
Group:
Registered Users
I need to implement GetFileNamesInDirectory("some_directory"); function, which i later can just:
std ::list< std :: string > getnames (const char * dir )
{
std ::list< std :: string > filenames ;
char ** rc = GetFileNameInDirectory ( "directory" );
if ( * rc == NULL )
{
printf ( "Error: Failed to enumerate filenames in directory '%s'\n" , dir );
return filenames ;
}
char ** i ;
std :: string file ;
for ( i = rc ; * i != NULL ; i ++ )
{
file = * i ;
printf ( " * We've got [%s].\n" , file . c_str ());
filenames . push_back ( file );
}
return filenames ;
}
And it should work on public versions of os4 (at least on FE), so no beta DOS's stuff can be used. How do it the best ?
Thanks
Re: What the best and fast way to get list of files/dirs in the directory
Posted on:
2018/11/18 14:43
#2
Just popping in
Joined: 2011/7/20 20:01Last Login
: 2021/11/23 14:38
From In the sticks
Group:
Registered Users
Something like this?
std ::list< std :: string > * getnames (const char * dir )
{
std ::list< std :: string > * filenames = new std ::list< std :: string >;
struct ExamineData * data_p = IDOS -> ExamineObjectTags ( EX_StringNameInput , dir , TAG_END );
if ( data_p )
{
if ( EXD_IS_DIRECTORY ( data_p ))
{
APTR context_p = IDOS -> ObtainDirContextTags ( EX_StringNameInput , dir ,
EX_DataFields , ( EXF_NAME | EXF_LINK | EXF_TYPE ),
TAG_END );
if ( context_p )
{
struct ExamineData * dat_p ;
/*
context_p takes care of deleting the returned dat_p objects
when we call ReleaseDirContext, so we mustn't call
FreeDosObject on them
*/
while (( dat_p = IDOS -> ExamineDir ( context_p )))
{
if ( EXD_IS_FILE ( dat_p ))
{
filenames -> push_back ( dat_p -> Name );
}
}
if ( ERROR_NO_MORE_ENTRIES == IDOS -> IoErr ())
{
success = TRUE ; /* normal exit */
}
else
{
IDOS -> Printf ( "Failed to obtain directory context for " % s "\n" , dir );
IDOS -> PrintFault ( IDOS -> IoErr (), NULL ); /* failure - why ? */
}
IDOS -> ReleaseDirContext ( context_p ); /* NULL safe */
} /* if (context_p) */
else
{
IDOS -> Printf ( "oops\n" );
IDOS -> PrintFault ( IDOS -> IoErr (), NULL ); /* no context - why ? */
}
} /* if (EXD_IS_DIRECTORY (data_p)) */
IDOS -> FreeDosObject ( DOS_EXAMINEDATA , data_p );
} /* if (data_p) */
return filenames ;
}
Re: What the best and fast way to get list of files/dirs in the directory
Posted on:
2018/11/18 16:06
#3
Home away from home
Joined: 2007/9/11 12:31Last Login
: Today 18:54
From Russia
Group:
Registered Users
Thanks, but getnames should be stay as it, its GetFileNameInDirectory i need to implement, which will return it all to char **rc
Re: What the best and fast way to get list of files/dirs in the directory
Posted on:
2018/11/18 21:04
#4
Supreme Council
Joined: 2006/11/19 18:16Last Login
: Today 3:01
From London, England
Group:
Webmasters Registered Users
There appears to be some source you can use here:
https://tpgit.github.io/Leptonica/sarray_8c_source.html Line 1778 starts the function you need...
Simon
Comments made in any post are personal opinion, and are in no-way representative of any commercial entity unless specifically stated as such.
----
http://codebench.co.uk
Re: What the best and fast way to get list of files/dirs in the directory
Posted on:
2018/11/19 8:03
#5
Just can't stay away
Joined: 2006/11/24 17:54Last Login
: 4/21 19:07
From Sanremo
Group:
Registered Users
@Rigo
is this library available also for amigaos4?
Re: What the best and fast way to get list of files/dirs in the directory
Posted on:
2018/11/19 14:20
#6
Just popping in
Joined: 2011/7/20 20:01Last Login
: 2021/11/23 14:38
From In the sticks
Group:
Registered Users
@kas1e
char ** GetFileNameInDirectory (const char * dir )
{
char ** filenames_pp = NULL ;
struct ExamineData * data_p = IDOS -> ExamineObjectTags ( EX_StringNameInput , dir , TAG_END );
if ( data_p )
{
if ( EXD_IS_DIRECTORY ( data_p ))
{
APTR context_p = IDOS -> ObtainDirContextTags ( EX_StringNameInput , dir ,
EX_DataFields , ( EXF_NAME | EXF_LINK | EXF_TYPE ),
TAG_END );
if ( context_p )
{
struct List * names_p = IExec -> AllocSysObjectTags ( ASOT_LIST , TAG_DONE );
if ( names_p )
{
struct ExamineData * dat_p ;
size_t num_entries = 0 ;
/*
context_p takes care of deleting the returned dat_p objects
when we call ReleaseDirContext, so we mustn't call
FreeDosObject on them
*/
while (( dat_p = IDOS -> ExamineDir ( context_p )))
{
if ( EXD_IS_FILE ( dat_p ))
{
char * copied_name_p = CopyToNewString ( dat_p -> Name );
if ( copied_name_p )
{
struct Node * node_p = IExec -> AllocSysObjectTags ( ASOT_NODE ,
ASONODE_Name , copied_name_p ,
ASONODE_Size , sizeof ( struct Node ),
TAG_DONE );
if ( node_p )
{
IExec -> AddTail ( names_p , node_p );
++ num_entries ;
}
}
}
}
if ( ERROR_NO_MORE_ENTRIES != IDOS -> IoErr ())
{
IDOS -> Printf ( "Failed to obtain directory context for " % s "n" , dir );
IDOS -> PrintFault ( IDOS -> IoErr (), NULL ); /* failure - why ? */
}
else
{
filenames_pp = ( char **) IExec -> AllocVecTags ( num_entries * sizeof ( char *), TAG_DONE );
if ( filenames_pp )
{
char * current_filename_pp = filenames_pp ;
struct Node * node_p = IExec -> GetHead ( names_p );
struct Node * next_node_p = NULL ;
while ( node_p )
{
if ( node_p -> ln_Name )
{
* current_filename_pp = node_p -> ln_Name ;
++ current_filename_pp ;
( node_p -> ln_Name = NULL ;
}
next_node_p = IExec -> GetSucc ( node_p );
IExec -> FreeSysObject ( ASOT_NODE , node_p );
node_p = next_node_p ;
}
}
}
IExec -> FreeSysObject ( ASOT_LIST , ( APTR ) list_p );
}
IDOS -> ReleaseDirContext ( context_p ); /* NULL safe */
} /* if (context_p) */
else
{
IDOS -> Printf ( "oopsn" );
IDOS -> PrintFault ( IDOS -> IoErr (), NULL ); /* no context - why ? */
}
} /* if (EXD_IS_DIRECTORY (data_p)) */
IDOS -> FreeDosObject ( DOS_EXAMINEDATA , data_p );
} /* if (data_p) */
return filenames_pp ;
}
char * CopyToNewString (const char * src_p )
{
char * dest_p = NULL ;
if ( src_p )
{
size_t len = strlen ( src_p );
dest_p = ( char *) IExec -> AllocVecTags ( len + 1 , TAG_DONE );
if ( dest_p )
{
strcpy ( dest_p , start_p );
}
}
return dest_p ;
}
Re: What the best and fast way to get list of files/dirs in the directory
Posted on:
2018/11/19 15:05
#7
Home away from home
Joined: 2007/9/11 12:31Last Login
: Today 18:54
From Russia
Group:
Registered Users
@all Thanks, it helps !
Currently Active Users Viewing This Thread:
1
(
0 members
and 1 Anonymous Users
)