[MSDOS] récup. nom fichier à partir arboresce

Fermé
nabil390 - 27 juin 2008 à 10:57
cchristian Messages postés 921 Date d'inscription lundi 21 janvier 2008 Statut Membre Dernière intervention 6 mars 2012 - 27 juin 2008 à 14:14
Bonjour,

Je souhaiterais récupérer le nom de fichier à partir de l'arboresence complète.

C'est à dire si j'ai "c:\temp\test.txt" je dois récupérer test.txt

J'ai pensé à un token dans une boucle for. Mais comment commencer par la fin de la chaine ? (je ne connais pas par avance la taille de l'arborescence...)

for /F "tokens=??????????? delims=\" %%a in ("c:\temp\test.txt ") do set Fichier=%%a
echo %Fichier%

2 réponses

cchristian Messages postés 921 Date d'inscription lundi 21 janvier 2008 Statut Membre Dernière intervention 6 mars 2012 130
27 juin 2008 à 13:13
Bonjour,

De mémoire, je n'ai momentanément pas d'environnement pour tester, ça doit donner quelque chose comme ça :

        SET "param_1=%1"
rem si %1 = c:\temp\ 

       SET  "param2=*"
        ............................ 
        .............................
        FOR              /R   "%param_1%"       %%F  IN  (*.%param_2%) DO     (
            SET               "nom_ext=%%~nxF"
            ECHO             !nom_ext!                              )


On doit récupérer tous les noms de fichiers (et leur extension) d'une même arborescence
1
merci beaucoup !

C'est exactement ça merci bcp cchristian !

for %%A in (C:\*) do (
echo %%~nxA
)

voici ce que j'ai trouvé aussi
%~I expands %I removing any surrounding quotes (")
%~fI expands %I to a fully qualified path name
%~dI expands %I to a drive letter only
%~pI expands %I to a path only
%~nI expands %I to a file name only
%~xI expands %I to a file extension only
%~sI expanded path contains short names only
%~aI expands %I to file attributes of file
%~tI expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I searches the directories listed in the PATH environment variable and expands %I to the fully qualified name of the first one found. If the environment variable name is not defined or the file is not found by the search, then this modifier expands to the empty string
0
cchristian Messages postés 921 Date d'inscription lundi 21 janvier 2008 Statut Membre Dernière intervention 6 mars 2012 130
27 juin 2008 à 14:14
Merci pour le retour et les informations qui l'accompagnent, à +, bon courage,
0