1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
/**
* Cette dmonstration explique comment l'utilisateur peut faire pour travailler
* avec les chemins d'acces des fichiers.
*
*------------------------------------------------------------------------------
* MLV_get_base_name: Renvoie la chaîne de caractères après le dernier séparteur
* / dans un chemin donné en paramètre.
*
* Cette fonction renvoie une chaîne de caractère.
*
* char* MLV_get_base_name(
* const char* path Le chemin à analyser.
* );
*
*------------------------------------------------------------------------------
* MLV_get_directory_name: Renvoie la chaîne de caractère s'étendnant jusqu'au
* dernier séparateur / du chemin donné en paramètre.
*
* Cette fonction renvoie une chaîne de caractère.
*
* char* MLV_get_directory_name(
* const char* path Le chemin à analyser.
* );
*
*------------------------------------------------------------------------------
* MLV_path_is_absolute: Teste si un chemin est absolu.
*
* Cette fonction renvoie 1 si le chemin est absolue, 0 sinon.
*
* int MLV_path_is_absolute(
* const char* path Le chemin à analyser.
* );
*
*------------------------------------------------------------------------------
* MLV_path_is_relative: Teste si un chemin est relatif.
*
* Cette fonction renvoie 1 si le chemin est relatif, 0 sinon.
*
* int MLV_path_is_relative(
* const char* path Le chemin à analyser.
* );
*
*------------------------------------------------------------------------------
* MLV_path_exists: Teste si le chemin corespond au chemin d'un fichier ou
* dossier existant.
*
* Cette fonction renvoie renvoie 1 si le chemin est associé à un dossier ou un
* fichier existant, 0 sinon.
*
* int MLV_path_exists(
* const char* path Le chemin à analyser.
* );
*
*------------------------------------------------------------------------------
* MLV_path_is_a_directory: Vérifie si un chemin est un associé à un répertoire.
*
* Cette fonction renvoie 1 si le chemin est associé à un dossier, 0 sinon.
*
* int MLV_path_is_a_directory(
* const char* path Le chemin à analyser.
* );
*
*------------------------------------------------------------------------------
* MLV_path_is_a_file: Vérifie si un chemin est un associé à un fichier.
*
* Cette fonction renvoie 1 si le chemin est associé à un fichier, 0 sinon.
*
* int MLV_path_is_a_file(
* const char* path Le chemin à analyser.
* );
*
*------------------------------------------------------------------------------
* MLV_build_path: Construit en concaténant différents textes, une chaine de
* caractère représentant un chemin dont les séparateurs
* corespondent aux spécifications de la plateforme sur laquel
* s'execute le programme.
*
* Cette fonction renvoie le chemin vérifiant les normes de la plateforme hôte.
*
* char* MLV_build_path(
* const char* first_element, La premiere chaîne à concatener
* ... les autres éléments à concatener
* );
*
*------------------------------------------------------------------------------
* MLV_get_current_directory: Determine le répertoire courant.
*
* Cette fonction renvoie le chemin du répertire courant.
*
* const char * MLV_get_current_directory( );
*
*------------------------------------------------------------------------------
* MLV_get_temporary_directory: Determine le répertoire temporaire.
*
* Le répertoire temporaire est le repertoire dans lequel les applications ont
* ont le droit d'ajouter et de modifier des fichiers.
* Ce répertoire génaralement vidé lorqsue la machine est étteinte.
*
* Cette fonction renvoie le chemin du répertire temporaire.
*
* const char * MLV_get_temporary_directory( );
*
*------------------------------------------------------------------------------
* MLV_get_home_directory: Determine le répertoire personnel de l'utilisateur
* courant.
*
* Cette fonction renvoie le chemin du répertire personnel.
*
* const char * MLV_get_home_directory( );
*
*------------------------------------------------------------------------------
*
*/
#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;
}
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012,2013 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
|