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

nabil390 -  
cchristian Messages postés 928 Statut Membre -
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%
A voir également:

2 réponses

cchristian Messages postés 928 Statut Membre 131
 
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
nabil390
 
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 928 Statut Membre 131
 
Merci pour le retour et les informations qui l'accompagnent, à +, bon courage,
0