Documentation de la bibliothèque MLV-0.5

advanced/12_paths.c

Cette dmonstration explique comment l'utilisateur peut faire pour travailler avec les chemins d'acces des fichiers.

#include <MLV/MLV_all.h>
#include <stdio.h>

//
// Attention ! 
// Pour pouvoir compiler ce programme sous windows et sous macintosh,
// il faut, pour la déclaration du main, respecter strictement la syntaxe
// suivante :
//
int main(int argc, char *argv[]){

        printf( "\n" );
        
        const char *current_directory, *temporary_directory, *home_directory;
        
        current_directory = MLV_get_current_directory( );
        printf("Répertoire courant : %s \n", current_directory);

        temporary_directory = MLV_get_temporary_directory( );
        printf( "Répertoire temporaire : %s\n", temporary_directory );

        home_directory = MLV_get_home_directory( );
        printf( "Répertoire personnel : %s\n", home_directory );

        const char* path = "./creature.png";
        if( MLV_path_exists( path ) ){
                printf("Le chemin %s existe.\n", path );
        }else{
                printf("Le chemin %s n'existe pas.i\n", path );
        }

        if( MLV_path_is_a_file( path ) ){
                printf("%s est un fichier.\n", path );
        }else{
                printf("%s n'est pas un fichier.\n", path );
        }

        if( MLV_path_is_a_directory( path ) ){
                printf("%s est un répertoire.\n", path );
        }else{
                printf("%s n'est pas un repertoire.\n", path );
        }

        if(
                MLV_path_is_absolute( path )
        ){
                printf( "%s  est un chemin absolu.\n", path );
        }else{
                printf( "%s est un chemin relatif.\n", path );
        }
        char* build_path = MLV_build_path( current_directory, path, NULL );
        if(
                MLV_path_is_relative( build_path )
        ){
                printf( "%s est un chemin relatif.\n", build_path );
        }else{
                printf( "%s est un chemin absolu.\n", build_path );
        }

        char* basename = MLV_get_base_name( build_path );
        char* dirname = MLV_get_directory_name( build_path );
        printf( "Dans la chemin précédent,\n" );
        printf( "La chaîne de texte se trouvant après le dernier séparateur / est : %s\n", basename );
        printf( "La chaîne de texte s'étendant jusqu'au dernier séparateur / est : %s\n", dirname );

        printf( "\n" );
        
        free( build_path );
        free( basename );
        free( dirname );

        return 0;
}