Difference between revisions of "Truxton child file get number of children"
(→Sample) |
|||
| (3 intermediate revisions by the same user not shown) | |||
| Line 13: | Line 13: | ||
=Return value= | =Return value= | ||
The number of children of this file. | The number of children of this file. | ||
| + | |||
| + | =Remarks= | ||
| + | Remember, not just directories can have child files. | ||
| + | Files can have children too. | ||
| + | Consider the [[Type_ZIP|Zip]] file. The children of a Zip archive are the files that were extracted from that Zip. | ||
=Sample= | =Sample= | ||
| − | <source lang="C" highlight=" | + | <source lang="C" highlight="28"> |
| − | void add_folder(uint64_t truxton, uint64_t parent_file) | + | void add_folder( uint64_t truxton, uint64_t parent_file ) |
{ | { | ||
| − | truxton_start_adding_files(truxton); | + | truxton_start_adding_files( truxton ); |
| − | uint64_t child = truxton_child_file_create(truxton); | + | uint64_t child = truxton_child_file_create( truxton ); |
char id[40]; | char id[40]; | ||
| − | truxton_file_get_id(parent_file, id, sizeof(id)); | + | truxton_file_get_id( parent_file, id, sizeof(id) ); |
| − | truxton_child_file_set_parent_id(child, id); | + | truxton_child_file_set_parent_id( child, id ); |
| − | truxton_child_file_set_type(child, Type_Directory); | + | truxton_child_file_set_type( child, Type_Directory ); |
| − | truxton_child_file_set_name(child, "Custom Exploits Folder"); | + | truxton_child_file_set_name( child, "Custom Exploits Folder" ); |
| − | + | uint64_t now = truxton_time_now(); | |
| − | + | truxton_child_file_set_created( child, now ); | |
| + | truxton_child_file_set_accessed( child, now ); | ||
| + | truxton_child_file_set_modified( child, now ); | ||
| − | + | truxton_child_file_set_origin( child, ORIGIN_GENERATED ); | |
| − | + | if ( truxton_child_file_save( child ) == 0 ) | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | if ( truxton_child_file_save(child) == 0 ) | ||
{ | { | ||
printf( "Failed to add child to Truxton\n" ); | printf( "Failed to add child to Truxton\n" ); | ||
| Line 50: | Line 48: | ||
else | else | ||
{ | { | ||
| − | uint32_t count = truxton_child_file_get_number_of_children(child_file); | + | uint32_t count = truxton_child_file_get_number_of_children( child_file ); |
| − | printf( "Child count is % | + | printf( "Child count is %" PRIu32 "\n", count ); |
} | } | ||
| − | truxton_child_file_destroy(child); | + | truxton_child_file_destroy( child ); |
} | } | ||
</source> | </source> | ||
| + | |||
| + | The <code>PRIu32</code> in the sample code above is a standard way of [https://en.wikipedia.org/wiki/C_data_types#Printf_and_scanf_format_specifiers formatting] a 32-bit unsigned integer in C. | ||
| + | Over the years, different compilers on different operating systems used different format specifiers for things, these <code>PRI</code> macros, along with some tricky string concatenation the compilers perform for you, allow you to maintain a single code base without a bunch of macro magic. | ||
Latest revision as of 03:04, 14 April 2024
This retrieves the number of children of this child file object.
This corresponds to the [NumberOfChildren] column of the [File] table.
Syntax
uint32_t truxton_child_file_get_number_of_children( uint64_t child_handle );
Parameters
child_handle
The handle created by the truxton_child_file_create or truxton_file_create_child call.
Return value
The number of children of this file.
Remarks
Remember, not just directories can have child files. Files can have children too. Consider the Zip file. The children of a Zip archive are the files that were extracted from that Zip.
Sample
void add_folder( uint64_t truxton, uint64_t parent_file )
{
truxton_start_adding_files( truxton );
uint64_t child = truxton_child_file_create( truxton );
char id[40];
truxton_file_get_id( parent_file, id, sizeof(id) );
truxton_child_file_set_parent_id( child, id );
truxton_child_file_set_type( child, Type_Directory );
truxton_child_file_set_name( child, "Custom Exploits Folder" );
uint64_t now = truxton_time_now();
truxton_child_file_set_created( child, now );
truxton_child_file_set_accessed( child, now );
truxton_child_file_set_modified( child, now );
truxton_child_file_set_origin( child, ORIGIN_GENERATED );
if ( truxton_child_file_save( child ) == 0 )
{
printf( "Failed to add child to Truxton\n" );
}
else
{
uint32_t count = truxton_child_file_get_number_of_children( child_file );
printf( "Child count is %" PRIu32 "\n", count );
}
truxton_child_file_destroy( child );
}
The PRIu32 in the sample code above is a standard way of formatting a 32-bit unsigned integer in C.
Over the years, different compilers on different operating systems used different format specifiers for things, these PRI macros, along with some tricky string concatenation the compilers perform for you, allow you to maintain a single code base without a bunch of macro magic.