Batch: list filenames without extension

Solved
Profile blocked -  
 Tym -
```batch
@echo off
for /f "delims=. tokens=1" %%f in ('dir .\dossier\*.ext /b /o:n') do echo %%f >> liste.txt
```

4 answers

  1. dubcek Posted messages 18627 Registration date   Status Contributor Last intervention   5 660
     
    hello
    you can also use the variable %~nI
    for /F "delims=" %I in ('dir /b') do @echo %~nI
    3
  2. Tym
     
    Hello,

    It is possible to perform this operation in a more elegant and certainly more reliable way:

    @ECHO OFF
    DEL liste.txt
    FOR /F %%I IN ('DIR .\folder\*.ext /B /O n') DO ECHO %%~nI >> liste.txt

    Indeed, the ~n format option allows you to get only the file name without the extension.

    The problem with the previous method is that if the file name contains a “.” (for example: “file.with.dots.ext”, the file name will be truncated (only “file” will remain in the previous example).

    I hope this will be useful to some.
    Best regards,

    Tym
    2
  3. cs-bilou Posted messages 836 Status Member 164
     
    Try it
    @echo off for /f "tokens=1 delims=." %%i in ('dir .\folder\*.ext /b /o n') do echo %%i >list.txt


    Keep me updated!

    Bilou.
    --
    There are days you shouldn't mess with me.
    And there are days every day!
    0
  4. Profile blocked
     
    Thank you very much, after a slight modification I got what I wanted:

    @echo off
    del liste.txt
    for /f "tokens=1 delims=." %%i in ('dir .\dossier\*.ext /b /o n') do echo %%i >>liste.txt

    The previous code listed the files in liste.txt but overwrote each time, so in the end I only had one name in liste.txt (the last one in the list).
    By adding >> instead of >, I had all the names, but if I reran the batch it would relist the already present files, hence the addition of a little del to delete the file before creating a new one.

    Thanks again for your precious help.
    0